Mail Archives: djgpp/1996/06/14/15:50:22
Reply to message 3905155 from GRENDEL AT ANANK on 06/12/96 3:39PM
> default:
> len += CharWidth(*walker++, curFont); // Here, the walker variable has
> // been everytime incremented
> // TWICE, not ONCE as it was
> // meant to be - what is wrong?
> }
I can almost guarantee that your problem results from the fact that
CharWidth is a macro, not a function. Examine the header file that
CharWidth is declared in carefully. This is a common pitfall with
macros, as illustrated by the following:
#define UMAX(a,b) ((a)>(b)?(a):(b))
Now, suppose you write a line like this:
x = UMAX(foo++, ++bar);
Look what it gets expanded to:
x = ((foo++)>(++bar)?(foo++):(++bar));
See the problem? No matter the result of the expression, either foo or bar
gets incremented twice. Stuff like this drives programmers nuts. :)
John
- Raw text -