q for the C hackers

Derek Martin invalid at pizzashack.org
Mon Aug 18 20:52:16 EDT 2003


On Mon, Aug 18, 2003 at 08:13:05PM -0400, Erik Price wrote:
> However, what is the convention in C?  There seem to be two fine
> ways of doing it -- using the preprocessor, or the const keyword:
> 
> #define NUMBER_OF_UNITS 8
> 
> const int NUMBER_OF_UNITS = 8;

Normally, the former way is what you'd use.  The latter construct is
most often used, in my experience, for function parameters which you
want to make sure are not modified by the function to which they
belong.  

I'm not a compiler guru, but I believe references to the #define'd
macro will cause the compiler to use immediate mode addressing, using
the value of the macro literally, requiring no additional storage
beyond what is required to store the opcode and its operands.  Whereas
the second method allocates storage in the segment of memory
associated with initialized data that hangs around, so that it can
contain the constant.

-- 
Derek D. Martin
http://www.pizzashack.org/
GPG Key ID: 0xDFBEAD02
-=-=-=-=-
This message is posted from an invalid address.
Replying to it will result in undeliverable mail.
Sorry for the inconvenience.  Thank the spammers.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.gnhlug.org/mailman/private/gnhlug-discuss/attachments/20030818/385d8248/attachment.bin


More information about the gnhlug-discuss mailing list