www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/06/14/08:18:46

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: <Pine DOT NEB DOT 3 DOT 93 DOT 960612212436 DOT 3438B-100000 AT ananke DOT amu DOT edu DOT pl>
NNTP-Posting-Host: mack.rt66.com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019