More NULL questions

Alex E. Pensky aep at ivan
Tue Oct 10 02:28:02 AEST 1989


In article <443 at shodha.dec.com> devine at shodha.dec.com (Bob Devine) writes:
>In article <5950001 at hpldola.HP.COM>, jg at hpldola.HP.COM (Joe Gilray) writes:
>> 2) Is there danger using
>>          int a, b;
>>          my_func(a, NULL, b);
>>    as apposed to
>>          my_func(a, (struct thing *)NULL, b);
>
>  You are in trouble if you do not use function prototypes
>if your system's pointer representation is not the same size
>as an int.  Moreover if the pointer has some strange bit
>pattern representation then the NULL may not be passed correctly.
>

Even if pointers and integers are the same size and have the same 
representation, you are still in trouble if your compiler passes int
parameters and pointer parameters via different mechanisms.  In such
a case, omitting both the prototype and the cast will mean that the *entire*
parameter list will be received incorrectly by my_func().

Yes, such compilers exist, and yes, I have been bitten by one after
forgetting the casts.

 -----------------------------------------------------------------------------
 Alex Pensky    ...!{cwjcc,decvax,pyramid,uunet}!abvax!aep       (216)646-5211
 Allen-Bradley Company             747 Alpha Drive, Highland Heights, OH 44143
 -----------------------------------------------------------------------------



More information about the Comp.lang.c mailing list