Seven Original Sins of K&R (Long)

Jeffrey T. Hutzelman jh4o+ at andrew.cmu.edu
Thu Sep 27 07:49:07 AEST 1990


rv at erix.ericsson.se (Robert Virding) writes:

>In article <12780 at sdcc6.ucsd.edu>, mautner at odin.ucsd.edu (Craig
>Mautner) writes:
>>              Seven Original Sins of K&R
>>                 by Philip J. Erdelsky
>
>>                          II
>>               Some compilers don't even object when 
>>you assign an integer constant to a pointer without a 
>>typecast, especially when the constant happens to be 
>>zero.  Don't blame the compiler.  The poor thing can't 
>>tell the difference between a zero integer constant and 
>>"NULL".
>
>According to the language definition assigning a zero to a pointer is
>perfectly legal, the compiler shouldn't complain. All C compilers I
>have seen will complain for any other integer. For the 50 million'th
>time in this group, there is no difference between zero and NULL.

I know of one compiler (on a 16-bit micro) that will not complain if you
use any other integer or long int.  Pointers on that machine are
(exaclty) same as unsigned long ints, and the compiler lets you say

void function(void)
{
unsigned char *pointer;
unsigned long int integer;

integer=0xE0C000;
for(pointer=integer;!(*pointer && 0x80););	/* wait for keypress */
printf("%#04x",*pointer & 0x7F);	/* strip off flag bit */
integer=0xE0C010;
*pointer=0;	/* reset keyboard latch and/or advance buffer */
}

which will wait for a keypress and print out its ASCII value (on an
Apple IIgs, under ORCA/C 1.0 or 1.1).
-----------------
Jeffrey Hutzelman
America Online: JeffreyH11
Internet/BITNET:jh4o+ at andrew.cmu.edu, jhutz at drycas.club.cc.cmu.edu

>> Apple // Forever!!! <<



More information about the Comp.lang.c mailing list