D
Disc Magnet
Is perror(s) just a macro to fprintf(stderr, "%s: %s\n", s,
strerror(errno)) ?
strerror(errno)) ?
Disc Magnet said:Is perror(s) just a macro to fprintf(stderr, "%s: %s\n", s,
strerror(errno)) ?
Disc Magnet said:Is perror(s) just a macro to fprintf(stderr, "%s: %s\n", s,
strerror(errno)) ?
perror() is a standard library function. For the actual definition,
grab a copy of
<http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf>
(that's the latest draft of the C standard) and read section 7.19.10.4.
Like any standard library function, it may additionally be defined as
a macro.
For a couple of reasons, the definition you present would not be
legal; first, the reference to s needs to be parenthesized, and
second, the behavior is different if s is a null pointer or points
to a null character.
I'm not sure how I'd define perror() as a macro that doesn't
potentially evaluate its argument more than once. And there's
probably not much reason to bother doing so; a call to perror()
isn't likely to be a performance bottleneck.
On 1/3/2011 5:45 PM, Keith Thompson wrote: [...]I'm not sure how I'd define perror() as a macro that doesn't
potentially evaluate its argument more than once. And there's
probably not much reason to bother doing so; a call to perror()
isn't likely to be a performance bottleneck.
Indeed. A program whose performance is limited by the speed at
which it can report its own errors most likely has problems other
than performance. ;-)
Well, in college, we had a FORTRAN compiler which was very efficient at
generating non-optimized code. (The point being, why waste CPU cycles
optimizing a program which is likely to not compile the first N times,
and which would likely be run only a single time once it actually did
compile.) It would generate extremely verbose, and extremely numerous,
error messages.
On 1/3/2011 5:45 PM, Keith Thompson wrote: [...]I'm not sure how I'd define perror() as a macro that doesn't
potentially evaluate its argument more than once. And there's
probably not much reason to bother doing so; a call to perror()
isn't likely to be a performance bottleneck.Indeed. A program whose performance is limited by the speed at
which it can report its own errors most likely has problems other
than performance. ;-)
Well, in college, we had a FORTRAN compiler which was very efficient at
generating non-optimized code. (The point being, why waste CPU cycles
optimizing a program which is likely to not compile the first N times, and
which would likely be run only a single time once it actually did compile..)
It would generate extremely verbose, and extremely numerous, error messages.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.