Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cwjcc!abvax!ivan!aep From: aep@ivan (Alex E. Pensky) Newsgroups: comp.lang.c Subject: Re: More NULL questions Message-ID: <914@abvax.UUCP> Date: 12 Oct 89 16:58:28 GMT References: <5950001@hpldola.HP.COM> <443@shodha.dec.com> <903@abvax.UUCP> <448@shodha.dec.com> Sender: news@abvax.UUCP Reply-To: aep@ivan.UUCP (Alex E. Pensky) Organization: Allen-Bradley Company, Inc.; Industrial Computer Division; Highland Hts. OH Lines: 36 In article <903@abvax.UUCP>, I, aep@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@shodha.dec.com> devine@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 -----------------------------------------------------------------------------