Date: Tue, 3 Oct 2000 10:52:42 -0700 From: Hannah C. Tang Newsgroups: uwash.class.cse142.bboard Subject: Re: assign "=" function This experiment with #define's is a good reminder to all that the syntax for #define's is slightly different than the syntax for, say, assignment for variables. When dealing with #define'd constants, you should assume that your #define'd constant will be *exactly* replaced in your program with its associated constant value (because #define's are a simply a text-substitution made by the pre-processor [you may want to review the slides on compilation if this is an unfamiliar term]). Assume you had the following program: #define FOO = 4; int main(void) { int bar = FOO + 3; printf("bar is %d\n", bar); return 0; } Notice the incorrect syntax for the #define. This means that the compiler believes that your program actually looks like: int main(void) { int bar = = 4; + 3; printf("bar is %d\n", bar); return 0; } Which you can see is incorrect. The correct way of defining FOO to be 4 would be: #define FOO 4 int main(void) { int bar = (FOO) + 3; printf("bar is %d\n", bar); return 0; } Because the text '4' will replace the text 'FOO' wherever it occurs in your program, this will yield the following program: int main(void) { int bar = (4) + 3; printf("bar is %d\n", bar); return 0; } Hannah ----- Original Message ----- Date: Mon, 2 Oct 2000 23:44:29 -0700 From: To: Newsgroups: uwash.class.cse142.bboard Subject: Re: assign "=" function The Line is: SUBTOTAL = (double)GALLEONS * EUROS_PER_GALLEON; and three such like it... but the problem wasn't with the above, I discovered, I typed in my #define incorrectly: #define EUROS_PER_GALLEON 60.0 I had entered as #define EUROS_PER_GALLEON = 60.0; which is incorrect... Thanks!