www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/05/12/18:40:54

Message-ID: <3739EEE2.F29D6A4F@unb.ca>
Date: Wed, 12 May 1999 17:13:06 -0400
From: Endlisnis <s257m AT unb DOT ca>
X-Mailer: Mozilla 4.51 [en] (Win95; U)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
To: djgpp AT delorie DOT com, salvador <salvador AT inti DOT gov DOT ar>
Subject: Re: New ANSI standard
References: <373752C8 DOT 2F62DBA9 AT swipnet DOT se> <3738204B DOT F5C29195 AT inti DOT gov DOT ar>
X-Info: BrunNet, Inc. 888-278-6638
Reply-To: djgpp AT delorie DOT com

salvador wrote:

> > 12 :     for(treD_vertice *p = first; p->next; p=p-next)
> > 13:          p->next = new treD_vertice(0,x,y,z)
> > 13 :     name lookup of  'p' changed for new ANSI 'for' scoping
> > 12 :    using obsolete binding at 'p'
>
> Is very clear and far from cryptic, the compiler is telling you that ANSI
> says p will be available *outside* the loop, but looks like you want it to
> be only inside the loop. Just avoid declaring the variable in this way,
> declare it outside the for and it will work in any compiler.

    That's not actually what it means.  It means that ANSI says that p will
only be available INSIDE the loop and he has used it AFTER/OUTSIDE the loop.
The new ANSI C++ rules for scope of a variable declared are INSIDE the for
loop.  If you try to use it outside (after) the for loop in DJGPP you will get
this message.

This program compiles fine:
-----------------------------
#include <stdio.h>

int main()
{
  double d;
  char Test[80];
  int p=6;

  for(int p=0; p<100; p++)
    printf("%d", p);
  p++;
}
---------------------------
    But, if the line 'int p=6;' is left out, that exact warning message will
be displayed.  In this case there are 2 different 'p' variables one with scope
inside the for loop and one with scope outside the for loop inside the main
function.
--
     (\/) Endlisnis (\/)
          s257m AT unb DOT ca
          Endlisnis AT HotMail DOT com
          ICQ: 32959047




- Raw text -


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