difference in compilers leads to stat() confusion
Jim Jagielski
jim at jagmac2.gsfc.nasa.gov
Tue Sep 18 04:39:45 AEST 1990
Well, 1st of all I want to apologize for the hubbub I created with my
premature posting about the behavior of stat() and lstat(). 10 minutes
after my posting, I figured out that the problem was in the way some
of the compilers I'm used to return struct's and unions. I quote
from one:
"For compatibility with the pcc implementation of C, returning a structure
or union from a function is performed in a 'non-reentrant' fashion. A struct
or union return value is returned by copying the return value into a static
variable in the fucntion. A pointer to this variable is then returned. If a
pointer was used as an argument to the function, then the pointer is set
equal to the returned value. If the argument was a structure, the calling
function will use the returned pointer to copy the static variable."
Hence, it made no difference WHERE the pointer pointed, it was set equal
to the struct that stat and lstat return. So the pointing to NULL is
not it at all, but in the way the compiler returns structs.
I've used this compiler for a while and was used to this way of doing it.
When I starting porting to A/UX cc, this behavior (which is compiler
dependant) the problem arose. Before really thinking about the code,
I wrote the posting to comp.unix.aux... 10 minutes after the posting
I started figuring out what was going on... of course, by then it was
too late.
It was a long time since using lstat() and stat() which return int
and the struct in the argument list. Anyway, this has reopened my eyes
to how tricky C is as far as portability... Even old dogs can (re)learn
(not so new) tricks.
--
=======================================================================
#include <std/disclaimer.h>
=:^)
Jim Jagielski NASA/GSFC, Code 711.1
jim at jagmac2.gsfc.nasa.gov Greenbelt, MD 20771
"Kilimanjaro is a pretty tricky climb. Most of it's up, until you reach
the very, very top, and then it tends to slope away rather sharply."
More information about the Comp.unix.aux
mailing list