DragonFly BSD
DragonFly users List (threaded) for 2006-05
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: [OT] C pointers: BSD versus Linux?

From: jwatson@xxxxxxxxxxxx
Date: Wed, 31 May 2006 13:37:52 -0500 (CDT)

> 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().

Jason Watson.

[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]