Re: q for the C hackers

2003-08-19 Thread Aaron Hope
On Mon, 2003-08-18 at 20:13, 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; Generally, the more the compiler knows, the better it

Re: q for the C hackers

2003-08-19 Thread Jerry Feldman
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Mon, 18 Aug 2003 20:53:01 -0400 Ray Cote [EMAIL PROTECTED] wrote: At 8:13 PM -0400 8/18/03, 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:

Re: q for the C hackers

2003-08-19 Thread Kevin D. Clark
Derek Martin [EMAIL PROTECTED] writes: 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

Re: q for the C hackers

2003-08-19 Thread Bob Bell
On Tue, Aug 19, 2003 at 02:50:01AM -0400, Aaron Hope [EMAIL PROTECTED] wrote: On Mon, 2003-08-18 at 20:13, 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

Re: q for the C hackers

2003-08-19 Thread Kevin D. Clark
Aaron Hope [EMAIL PROTECTED] writes: On Mon, 2003-08-18 at 20:13, 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;

Re: q for the C hackers

2003-08-19 Thread Bob Bell
On Tue, Aug 19, 2003 at 09:07:23AM -0400, Kevin D. Clark [EMAIL PROTECTED] wrote: Another possibility is to use enums, i.e.: enum { BUFSIZE=512 }; char arr[BUFSIZE]; I use this frequently, and I recommend this. One advantage of enum's is that symbolic debuggers can display

Re: Reply-To munging (was: q for the C hackers)

2003-08-19 Thread Jeff Macdonald
On Tue, 2003-08-19 at 09:53, [EMAIL PROTECTED] wrote: To avoid rehashing, here are the two arguments: Reply-To Munging Considered Harmful http://www.unicom.com/pw/reply-to-harmful.html Reply-To Munging Considered Useful http://www.metasystema.org/essays/reply-to-useful.mhtml Thank God

Re: q for the C hackers

2003-08-19 Thread David Long
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; I'm just interested in hearing about whether one is more appropriate than the other in some

Reply-to header, yet again (was Re: q for the C hackers)

2003-08-19 Thread Derek Martin
On Tue, Aug 19, 2003 at 02:50:01AM -0400, Aaron Hope wrote: BTW, Is there a reason why mailman isn't configured to set the reply-to header? Yes. We've had this holy war before, and the (small) majority of list members were against reply-to. The logical argument: Setting the reply-to header

Reply-To munging (was: q for the C hackers)

2003-08-19 Thread bscott
On Tue, 19 Aug 2003, at 2:50am, [EMAIL PROTECTED] wrote: BTW, Is there a reason why mailman isn't configured to set the reply-to header? Some time back, the list took a vote, and more people voted harmful then useful, and we went with the plurality. To avoid rehashing, here are the two

Re: q for the C hackers

2003-08-19 Thread Erik Price
Tom Fogal wrote: I'm just interested in hearing about whether one is more appropriate than the other in some contexts. Thanks. Generally, I would use #defines for anything but function parameters. Passing things as a constant reference (const type val) is a good way to avoid passing a large

Re: q for the C hackers

2003-08-19 Thread Kevin D. Clark
Tom Fogal [EMAIL PROTECTED] writes: the const int way stores the variable in read only memory, and thus, IMO is a waste of memory. Also, it would be required to do a memory lookup when accessing the value. The value *might* get stored in read-only memory. The standard doesn't require this.

Re: q for the C hackers

2003-08-19 Thread Tom Fogal
Tom Fogal wrote: I'm just interested in hearing about whether one is more appropriate than the other in some contexts. Thanks. Generally, I would use #defines for anything but function parameters. Passing things as a constant reference (const type val) is a good way to avoid

Re: q for the C hackers

2003-08-19 Thread Erik Price
Tom Fogal wrote: The bit about memory addresses instead of some large value is entirely correct. Practically however, this will only be better when passing a value larger than the register size of the architecture you are on. For instance, on ix86 linux, all pointers are 32-bit integers. Thus

Re: q for the C hackers

2003-08-19 Thread Kevin D. Clark
Tom Fogal [EMAIL PROTECTED] writes: The const is purely optional; you could just as easily remember yourself that 'hey, i dont want to change that value in this function' and simply not do it. The justification i was given for such usage is that someone who is not you can quickly look at the

Re: q for the C hackers

2003-08-19 Thread David Long
ANSI C allows the implementation to store duplicate strings in the same memory location at runtime. I stand corrected. My claim came from a very old document. The only (draft) version of the ISO standard I have at my finger tips says it is now unspecified. I think my argument still stands

Re: q for the C hackers

2003-08-19 Thread Aaron Hope
On Tue, 2003-08-19 at 08:46, Bob Bell wrote: Actually, the following is valid C99: const int m = 10; int foo(int n) { char s[n]; char t[m]; ... } Yes, C99 supports variable sized arrays, but that's not always what you

q for the C hackers

2003-08-18 Thread Erik Price
When I want to define a constant value in Java, such as a magic number, I usually use public static final: public static final int NUMBER_OF_UNITS = 8; However, what is the convention in C? There seem to be two fine ways of doing it -- using the preprocessor, or the const keyword:

Re: q for the C hackers

2003-08-18 Thread Derek Martin
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

Re: q for the C hackers

2003-08-18 Thread Ray Cote
At 8:13 PM -0400 8/18/03, 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; This tends to be the nicer way to do it these days. Biggest

Re: q for the C hackers

2003-08-18 Thread Derek Martin
On Mon, Aug 18, 2003 at 08:52:16PM -0400, Derek Martin wrote: 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. Er,