Xref: news2.mv.net comp.os.msdos.djgpp:4982 From: broeker AT PROBLEM_WITH_INEWS_DOMAIN_FILE (Hans-Bernhard Broeker) Newsgroups: comp.os.msdos.djgpp Subject: Re: Is post-increment a pre-increment? Date: 14 Jun 1996 11:46:28 GMT Organization: RWTH -Aachen / Rechnerbetrieb Informatik Lines: 31 Message-ID: <4prjek$8l7@news.rwth-aachen.de> References: NNTP-Posting-Host: axpcl6.physik.rwth-aachen.de To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Mark Habersack (grendel AT ananke DOT amu DOT edu DOT pl) wrote: [...] > 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? This heavily looks like a case of macro parameters with side-effects. If CharWidth is a macro that evaluated its first parameter twice, this would be a perfect explanation of the behvaviour you describe. Just imagine Charwidth were something like this: #define CharWidth(char, font) ((is_alnum(char)? (font)[char].width : 0) Now, if 'char' is '*walker++', it will get incremented twice if is_alnum(char) is true. This is a well-known cause of problems with C, but can be hard to spot sometimes. The fix is exactly the one you proposed (pass first, then increment), and can be put as a rule like this: Don't use an expression with side effects as a macro parameter! Hans-Bernhard Broeker (Aachen, Germany)