Mail Archives: djgpp/1996/06/14/08:18:46
In article <Pine DOT NEB DOT 3 DOT 93 DOT 960612212436 DOT 3438B-100000 AT ananke DOT amu DOT edu DOT pl>,
Mark Habersack <grendel AT ananke DOT amu DOT edu DOT pl> wrote:
>
>Hi,
> Today, debugging some code, I have found strange behaviour of the
>post-increment operator. Maybe it is a bug (or "hidden feature" how Microsoft
>would describe it) and maybe just a side effect which I don't understand.
>Anyway, here's what was going on:
<snip>
>int len = 0;
>char* walker = text; // Text is a char* argument passed to the func
>
>while(*walker)
> switch(*walker)
> {
> case '%':
> switch(*(++walker))
> {
> .
> . // Do the processing of formatting codes
> .
> }
Howzabout a "break;" here?
> 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?
> }
>
> Later on I changed the offending line to
> len += CharWidth(*walker, curFont);
> walker++;
> and everything worked just fine. Where lies the error - is it my ignorance or
>a bug or side effect?
I don't see why this would fix it as "*p++" is the same as "*p; p++"
--Brennan
--
brennan AT rt66 DOT com | "He say you Brade Runna!"
- Raw text -