delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/24/00:38:42

From: Jason Dagit <thedagit AT mail DOT coos DOT or DOT us>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Linked lists
Date: Mon, 23 Mar 1998 17:38:02 -0800
Organization: Dagit Enterprises
Lines: 41
Message-ID: <35170E7A.ADEF7B81@mail.coos.or.us>
References: <3514D2FB DOT 3885 AT swipnet DOT se> <3515A9CC DOT 3F205D05 AT alcyone DOT com> <3515B2A7 DOT B238AA6B AT concentric DOT net>
Reply-To: thedagit AT mail DOT coos DOT or DOT us
NNTP-Posting-Host: coosbay3-22.transport.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

D. Huizenga wrote:
> A small note:
>  Besides having the advantage of
>  being able to access the variable outside of the
>  loop, according to a previouse thread in this group
>  the second way has the added advantage of being
>  much faster than the first. If I remember coorectly,
>  this is because the variable is declared only once,
>  opposed to being declared newly each time the code
>  goes back to the top of the loop.
>
Well, I think that would be true if the code was changed to:

for(int k = 0;...;...)
   for(int i = 0;...;...)
   {
	//i has scope here
   }

Otherwise as I see it, it would "forget" which iteration it was on. 
That is, if i was re-initailized every time in the original code then
how would it be incremented?  How could you check the value?  I don't
know what the style gurus would say about for(int i = 0;...;...), but I
think it is just bad.  I've also heard their is some problems with that
syntax with certain compilers.  And if your code isn't as portable as it
could be then you are defeating the purpose of C/C++, IMHO.  I wish it
was possible to REASONABLY add VESA or some other graphics standard to
C/C++ so that porting programs that use graphics would be easier.  It
would be nice if more API's were in the standard, but you can't have
everything I guess.

> > The new C++ standard decrees that scoped variables are local only to
> > their scope.  i.e.,
> >
> >     for (int i = 0; ...; ...)
> >     {
> >         // i has scope here
> >     }
> >
> >     i = 0; // i does not have scope here; this is illegal
> >

- Raw text -


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