Thou shalt have no other gods before the ANSI C standard

From: D. J. Bernstein (djb_at_cr.yp.to)
Date: 02/02/05


Date: Wed, 2 Feb 2005 21:19:27 +0000 (UTC)

Douglas A. Gwyn wrote:
> The fact is, using calloc to initialize non-integer values is *wrong*

Are you next going to claim that every program using POSIX system calls
is ``wrong''? After all, the C standard doesn't guarantee they'll work!

Perhaps your response will be that the C spec and the POSIX spec are
equally worshipped in your religion. Well, suppose I write a C program
that runs perl---which isn't guaranteed to work by either spec. Is that
program ``wrong''?

I'll readily agree that the all-0-bytes representation of NULL isn't
guaranteed by the C standard. I'll also agree that there was, once upon
a time, an obscure C implementation that, for silly reasons, used a
different representation of NULL. But this doesn't mean that programs
relying on the all-0-bytes representation are ``wrong.'' It simply means
that they won't work with goofy implementations of C.

> and every competent C programmer knows it

The vast majority of C programmers are writing code for PCs, Macs, Suns,
etc., running Windows, Linux, MacOS, BSD, etc., all of which guarantee

   * an all-0-bytes representation of NULL,
   * 8-bit char,
   * 16-bit short,
   * 32-bit int (the 286 is dead), and
   * IEEE single-precision 32-bit float (UNICOS is dead),

among other things. Taking advantage of these guarantees is convenient
for the programmer and doesn't sacrifice any real-world portability.

---D. J. Bernstein, Associate Professor, Department of Mathematics,
Statistics, and Computer Science, University of Illinois at Chicago



Relevant Pages

  • Re: WaitForSingleObject() will not deadlock
    ... But what is TSO? ... Technical Standard Order, a minimum performance standard issued by the FAA for certain ... have been more commonly referred to as the "cache coherency" ... A mutex is sufficient to guarantee visibility, ...
    (microsoft.public.vc.mfc)
  • Re: Thou shalt have no other gods before the ANSI C standard
    ... >Are you next going to claim that every program using POSIX system calls ... the C standard doesn't guarantee they'll work! ... Did you notice any guarantees with your compilers on these platforms? ...
    (sci.crypt)
  • Re: Segfault City
    ... Realizing ... What, if anything, can it be guaranteed will be> '9' in standard C? ... there /isn't/ any guarantee of a character greater than '9' in C. ...
    (comp.lang.c)
  • Re: Thou shalt have no other gods before the ANSI C standard
    ... >Are you next going to claim that every program using POSIX system calls ... the C standard doesn't guarantee they'll work! ... you don't really know the "vast majority of C programmers" ...
    (sci.crypt)
  • Re: Segfault City
    ... Andrew Poelstra wrote: ... What, if anything, can it be guaranteed will be> '9' in standard C? ... Perhaps I should have studied English more in high school at East ... there /isn't/ any guarantee of a character greater than '9' in C. ...
    (comp.lang.c)