Mail Archives: djgpp/1997/02/20/07:13:59
: solution... "WHENEVER using fixed point math make profuse use of
: brackets!!!" Like the following:
: #define putpixel(x,y,c) \
: _farpokeb(_dos_ds, 0xA0000+(y)*320+(x), (c));
YM "Whenever using #define, make profuse use of brackets" :)
It's a big problem; I think it's generally pretty safe if you enclose
all parameters in a #define in at least one set of brackets. If you're
writing an expression, you should also enclose the entire #define in
brackets. For example,
#define subtract1(a,b) a-b /* very bad */
#define subtract2(a,b) (a)-(b) /* better */
#define subtract3(a,b) ((a)-(b)) /* best */
The point about subtract2 still not being perfect is that, for example,
3*subtract2(4,2) => 3*(4)-(2) /* this is not likely to be what was meant */
3*subtract3(4,2) => 3*((4)-(2)) /* what was probably intended */
Somewhere in the info docs they address this common confusion, I think.
--
George Foot <gfoot AT mc31 DOT merton DOT ox DOT ac DOT uk>
Merton College, Oxford.
- Raw text -