Xref: news2.mv.net comp.os.msdos.djgpp:4956 From: brennan AT mack DOT rt66 DOT com (Brennan "Bas" Underwood) Newsgroups: comp.os.msdos.djgpp Subject: Re: Is post-increment a pre-increment? Date: 13 Jun 1996 14:08:26 -0600 Organization: None, eh? Lines: 44 Message-ID: <4ppsfq$ek5@mack.rt66.com> References: NNTP-Posting-Host: mack.rt66.com To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp In article , Mark Habersack 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: >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!"