[comp.unix.aux] No more, I promise!!!

jim@jagmac2.gsfc.nasa.gov (Jim Jagielski) (09/19/90)

The problem all started when I ported a program using the GreenHills C
Compiler to cc (to use shared libraries). The error happened at stat and
lstat. When I saw the problem, I took a very casual glance at the man
pages to refresh my memory about stat. I saw "*sbuf" and ASSUMED that
although stat had a return type int, it also returned a pointer to
struct stat. I was passing a pointer, so why didn't it work? Maybe stat
and lstat was doing soemthing to the pointer 1st (accessing memory)...?
So I set it equal to NULL to insure that it was "pointing to nothing"
(i.e. a NULL pointer). Nothing.

So I did what every normal person would do... I freaked :)

After the posting, I started thinking (what I SHOULD have done in the 1st
place). Looking back at the mans, I discovered that although stat expects
a pointer to struct, it assumes that space is AVAILABLE at the location
where the pointer points (stat is one of those beasts that "returns" a
struct, fully "filled"). Okay, so I now know why it didn't work... I
didn't call it right. So WHY did it work with the GreenHills and VaxC
compilers... I recall a few compilers handling pointer = NULL in a unique
way. 0 would be a sort of common or union space, sort of being able to
get space without using malloc (assuming, of course, that no one else
was using it, i.e., no other variable or function). This turned out not
to be it, of course. The real reason was found in the manual quote I posted
a few postings ago.

So basically, the problem was that the code did what I told it to, but not
what I wanted it to do... I'm sure this has happened to everyone (except
a few perfect few :). In fact, if I just would have looked in K&R, V2, I
would have seen the answer instantly (or if I would have though of time()),
and would not have bugged so many people.

I'm sorry for all the wasted bandwidth on this... I made a stupid mistake.
Instead of just being told that, I was told that I was incompetent... big
difference.

Anyway, there is a lesson I've learned. RTFM 1st. There is also another.
No one is perfect. There is also one more. Be kind to others...
--
=======================================================================
#include <std/disclaimer.h>
                                 =:^)
           Jim Jagielski                    NASA/GSFC, Code 711.1
     jim@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."