time(0L) - I'm sorry, I can't resist

Barry Margolin barmar at think.com
Thu May 23 14:00:54 AEST 1991


In article <1200 at applix.com> scotte at applix.UUCP (Scott Evernden) writes:
>Name for me any modern computer in any kind of common use which will
>barf at:
>	time(0L);

I frequently respond to this frequent question with one or two machines I'm
familiar with, but I'm not going to do that this time.  Suffice it to say
that there *are* systems where the null pointer is not implemented as the
same bit pattern as 0L.

No, these systems are not "in common use".  90% of all C programs are
probably running on 80*86, 680x0, VAX, and SPARC processors, but does that
mean that all other systems should be ignored?

Prototypes are the most appropriate solution to this problem.  With a
prototype in scope, the above call works right on any ANSI-conforming
implementation.  But if you need to be portable to pre-ANSI
implementations, then is "(char *)0" so hard to write?  Not only does it
inform the compiler of the correct code to generate (in implementations
that care), but it also makes the intent clearer to *human* readers of the
code.  What's the point of looking for a way around something that's so
clearly right?
-- 
Barry Margolin, Thinking Machines Corp.

barmar at think.com
{uunet,harvard}!think!barmar



More information about the Comp.lang.c mailing list