E
Eric Sosman
CJ wrote On 11/19/07 14:43,:
The original ANSI Standard was adopted in 1989. Uptake
was rapid (breathtakingly so, by comparison with that of the
1999 revision), but even so it took compiler and library
suppliers a while to grok the Standard, figure out how to
smooth the transition for existing customers, and get new
versions out -- maybe three, four years passed before ANSI-
conforming (by then, ISO-conforming) implementations were
widely available. Let's grant maximum leeway and use four
years; then the older implementations you mention had been
supplanted by 1993.
Windows NT 3.1 shipped in 1993. Question: When you
write software for Windows today, are you careful to stick
to the NT 3.1 API's to enhance portability?
Mosaic 1.0 shipped in 1993. Question: When you write
HTML today, are you careful to use only HTML 1.0 tags to
enhance cross-browser portability?
In the days when malloc() returned `char*', C did not
have prototypes; do you avoid prototypes for portability's
sake? In the days when malloc() returned `char*', there
was no <stdarg.h>; do you shun variadic functions? In the
days when malloc() returned `char*', there was no `void',
no `long double', no stringizing `#', no token-pasting `##',
no '\a' or '\v', no <limits.h>, ... Do you stay away from
all these in an attempt to cater to obsolete compilers and
libraries?
If by some peculiar twist of fate your code winds up
being compiled with Paleolithic library headers, do you
think it's better to have a cast already in place to make
sure you don't get warned of the problem than to be alerted
by a helpful diagnostic?
If you answered "Yes" to any of these questions, you
should cast the result of malloc. After fifteen years on
the island with Gilligan and the gang, a certain amount
of loony behavior is to be expected.
[... cast malloc's result or not?]
In many older implementations of the standard library, malloc is defined
to return a char * rather than a void *, so including the cast makes
your program more portable.
The original ANSI Standard was adopted in 1989. Uptake
was rapid (breathtakingly so, by comparison with that of the
1999 revision), but even so it took compiler and library
suppliers a while to grok the Standard, figure out how to
smooth the transition for existing customers, and get new
versions out -- maybe three, four years passed before ANSI-
conforming (by then, ISO-conforming) implementations were
widely available. Let's grant maximum leeway and use four
years; then the older implementations you mention had been
supplanted by 1993.
Windows NT 3.1 shipped in 1993. Question: When you
write software for Windows today, are you careful to stick
to the NT 3.1 API's to enhance portability?
Mosaic 1.0 shipped in 1993. Question: When you write
HTML today, are you careful to use only HTML 1.0 tags to
enhance cross-browser portability?
In the days when malloc() returned `char*', C did not
have prototypes; do you avoid prototypes for portability's
sake? In the days when malloc() returned `char*', there
was no <stdarg.h>; do you shun variadic functions? In the
days when malloc() returned `char*', there was no `void',
no `long double', no stringizing `#', no token-pasting `##',
no '\a' or '\v', no <limits.h>, ... Do you stay away from
all these in an attempt to cater to obsolete compilers and
libraries?
If by some peculiar twist of fate your code winds up
being compiled with Paleolithic library headers, do you
think it's better to have a cast already in place to make
sure you don't get warned of the problem than to be alerted
by a helpful diagnostic?
If you answered "Yes" to any of these questions, you
should cast the result of malloc. After fifteen years on
the island with Gilligan and the gang, a certain amount
of loony behavior is to be expected.