[OT] C pointers: BSD versus Linux?

jwatson at slashopt.net jwatson at slashopt.net
Wed May 31 13:24:27 PDT 2006


> Hi compiler/OS gurus,
>
> Please consider this trivial fragment of c code which I've
> written in two different styles:
>
> Style 1:
> time_t t*;
> time(t);
>
> Style 2:
> time_t t;
> time(&t);
>
> My puzzle is this:  on *BSD these two different styles work
> identically -- but on my linux boxes Style 1 produces a
> run-time error, while Style 2 works as expected.
>
> Anyone here know why this difference?
>
> Thanks for any clues!

My experience is that *BSD's malloc and pointer stuff is designed to be as
safe as possible by default, and will try to fix and correct any common
mistakes you will make.  The short answer is that BSD will figure out
where you are screwing up and allow it to work. Linux gives you total
freedom to screw your self over.

Also, style 1 is technically "incorrect" since you never allocated the
memory that t is pointing to before passing it into time().

Signed,
Jason Watson.






More information about the Users mailing list