Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!columbia!rutgers!clyde!cbatt!cwruecmp!hal!ncoast!kent From: kent@ncoast.UUCP (Kent Williams) Newsgroups: comp.lang.c Subject: NULL pointers Message-ID: <1696@ncoast.UUCP> Date: Fri, 14-Nov-86 09:34:56 EST Article-I.D.: ncoast.1696 Posted: Fri Nov 14 09:34:56 1986 Date-Received: Sun, 16-Nov-86 00:29:43 EST Distribution: comp Organization: Cleveland Public Access UNIX, Cleveland, OH Lines: 57 RE : The Use of NULL Maybe I'm ignorant, but the use of NULL is a constant source of pain for which it seems there is a simple solution to wit /* local.h - include after other include modules */ #ifdef HASVOID #define NULL ((void *)0) #else #define NULL 0L #endif . . . If NULL is typed to have the size of the largest possible object that it will be assigned to, it will be 'narrowed' to fit into whatever object you are assigning it to. As a matter of style, NULL for me seems to be something that should only be used as a pointer object. I get sick to my stomach every time I see int stupid(cp) char *cp; { *cp = NULL; } Do they REALLY mean they want a 0 poked into the character pointed to by cp, or did they mean cp = NULL, or what? If you have void type, then a void pointer should be a 'universal pointer,' i.e. assignable to any pointer variable, but un-dereference-able without a cast to a non-void type. Also, malloc and calloc should be of the type void pointer, so that you don't get invalid pointer assignment complaints from compilers. It seems supremely asinine that Microsoft C complains about struct nameless x; x = malloc(sizeof(struct nameless)); All of the above suggestions should be very portable - if they're not, let me know why. AND another thing - why isn't it standard practice to bracket the standard include files with the following? /* stdio.h */ #ifndef STDIO_H_INCLUDED #define STDIO_H_INCLUDED /* rest of stdio.h */ #endif This would mean that you could re-include things without complaints from the pre-processor and compiler. These opinions are my own, and reflect the views only of me.