🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2524

Re: New treatment of 'for (int i ...'

#2524
From: Fergus Henderson
Date: Sat, 11 Nov 1995 08:57
43 lines
1634 bytes
mikes@forte.com (Mike Schilling) writes:

>Fergus Henderson (fjh@munta.cs.mu.OZ.AU) wrote:
>: There is a neat hack which gives you the new behaviour with old compilers:
>:
>:   #ifdef USE_HACK_FOR_NEW_FOR_SCOPE
>:   #define for(x) if (0) ; else for(x)
>:   #endif
>:
>: (Did I get that right this time?)
>Try this with:
>
>    for (i = 0, p = string; *p; i++, p++)

Yes, that macro hack does have its disadvantages.
In cases like this, you can use some extra parentheses:

     for ((i = 0, p = string); *p; (i++, p++))

For cases like

     for (int i = 0, j = 0; a[i] != a[j]; i++, j++)
	  ^^^

it's a bit trickier - you have to write something like

     int i = 0, j = 0;
     for (; a[i] != a[j]; (i++, j++))

or
     int i, j;
     for (i = j = 0; a[i] != a[j]; (i++, j++))

--
Fergus Henderson             	WWW: http://www.cs.mu.oz.au/~fjh
fjh@cs.mu.oz.au              	PGP: finger fjh@128.250.37.3


---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <9531518.11584@mulga.cs.mu.OZ.AU>
Path: arc1-ca.pugleaf.net!info.ucla.edu!agate!agate!Matt
References: <9531318.2076@mulga.cs.mu.OZ.AU> <9511102010.AA05887@omega.forte.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!info.ucla.edu!agate!agate!Matt
From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Newsgroups: comp.std.c++
Subject: Re: New treatment of 'for (int i ...'
Date: 11 Nov 1995 08:57:20 GMT
Organization: Computer Science, University of Melbourne, Australia
Approved: Matt@Austern
Message-ID: <9531518.11584@mulga.cs.mu.OZ.AU>
References: <9531318.2076@mulga.cs.mu.OZ.AU> <9511102010.AA05887@omega.forte.com>
NNTP-Posting-Host: austern.hip.berkeley.edu