More NULL questions
Alex E. Pensky
aep at ivan
Fri Oct 13 02:58:28 AEST 1989
In article <903 at abvax.UUCP>, I, aep at ivan (Alex E. Pensky) wrote:
>> 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().
In article <448 at shodha.dec.com> devine at shodha.dec.com (Bob Devine) responds:
> What different mechanisms? C only supports call-by-value for
>parameters (I'm ignoring the special casing of arrays here). How
>can pointers be passed differently than ints? It sounds like you
>used a broken compiler.
Imagine this: Compiler supports passing in registers rather than
on the stack. Motorola 68xxx compiler. Scalars are passed in data
registers, pointers in address registers.
foobar( (char *)NULL ) passes a 32-bit zero in register A2, but
foobar( NULL ) passes a 32-bit zero in register D3
If foobar() is written to expect a char *, it will look for its argument
in register A2. Who knows what's in A2, in the latter case above?
Welcome to the Tektronix CLANDS II cross-development system!! No, the
compiler is not broken, it's just trying to make my program run faster
by reducing function call overhead.
Moral of the story: If you ever assume that a cast is not really necessary
when mixing types, you are writing code that is not only machine-specific,
it is also COMPILER-SPECIFIC.
-----------------------------------------------------------------------------
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