Thread: [GD-General] Variables scope
Brought to you by:
vexxed72
From: CAVEY G. <GER...@sg...> - 2004-02-04 09:11:15
|
Hi there Few days ago i switched to Visual c++ 6.0 and this is what i = discovered. The compiler accept the following C++ code : //first loop for(unsigned long b=3D0;b<MeshesArray[current].VerticesCount;b++) { ...//processing } //second loop=20 for( b=3D0;b<not_used*3;b++) { ... } But i thiink i should write the second FOR like this "for(unsigned long b=3D0;b<not_used*3;b++)" (i mean i should redeclare 'b' because it came = out of scope) When i tried the compiler answered me "error redefinition ..." !!! Did i forget to set an option ;it is a bit strange isn t it? Greetings=20 GC=20 ************************************************************************= * Ce message et toutes les pieces jointes (ci-apres le "message") sont confidentiels et etablis a l'intention exclusive de ses destinataires. Toute utilisation ou diffusion non autorisee est interdite.=20 Tout message electronique est susceptible d'alteration.=20 SG Asset Management et ses filiales declinent toute responsabilite au = titre de ce message s'il a ete altere, deforme ou falsifie. D=E9couvrez l'offre et les services de SG Asset Management sur le site www.sgam.fr=20 ******** This message and any attachments (the "message") are confidential and intended solely for the addressees. Any unauthorised use or dissemination is prohibited.=20 E-mails are susceptible to alteration. =20 Neither SG Asset Management nor any of its subsidiaries or affiliates = shall be liable for the message if altered, changed or falsified.=20 ************************************************************************= * |
From: Jamie F. <ja...@qu...> - 2004-02-04 09:41:48
|
that's just the way msvc6 is and always has been (i think maybe they added an option at some point to switch the behaviour?), its scoping of variables declared in for statements just violates the standard because microsoft (obviously!) know better. Fortunately they recovered in msvc7. jamie -----Original Message----- From: gam...@li... [mailto:gam...@li...]On Behalf Of CAVEY GERARD Sent: 04 February 2004 09:11 To: 'gam...@li...' Subject: [GD-General] Variables scope Hi there Few days ago i switched to Visual c++ 6.0 and this is what i discovered. The compiler accept the following C++ code : //first loop for(unsigned long b=0;b<MeshesArray[current].VerticesCount;b++) { ...//processing } //second loop for( b=0;b<not_used*3;b++) { ... } But i thiink i should write the second FOR like this "for(unsigned long b=0;b<not_used*3;b++)" (i mean i should redeclare 'b' because it came out of scope) When i tried the compiler answered me "error redefinition ..." !!! Did i forget to set an option ;it is a bit strange isn t it? Greetings GC ************************************************************************* Ce message et toutes les pieces jointes (ci-apres le "message") sont confidentiels et etablis a l'intention exclusive de ses destinataires. Toute utilisation ou diffusion non autorisee est interdite. Tout message electronique est susceptible d'alteration. SG Asset Management et ses filiales declinent toute responsabilite au titre de ce message s'il a ete altere, deforme ou falsifie. Découvrez l'offre et les services de SG Asset Management sur le site www.sgam.fr ******** This message and any attachments (the "message") are confidential and intended solely for the addressees. Any unauthorised use or dissemination is prohibited. E-mails are susceptible to alteration. Neither SG Asset Management nor any of its subsidiaries or affiliates shall be liable for the message if altered, changed or falsified. ************************************************************************* ------------------------------------------------------- The SF.Net email is sponsored by EclipseCon 2004 Premiere Conference on Open Tools Development and Integration See the breadth of Eclipse activity. February 3-5 in Anaheim, CA. http://www.eclipsecon.org/osdn _______________________________________________ Gamedevlists-general mailing list Gam...@li... https://lists.sourceforge.net/lists/listinfo/gamedevlists-general Archives: http://sourceforge.net/mailarchive/forum.php?forum_idU7 |
From: Jorrit T. <Jor...@uz...> - 2004-02-04 09:46:52
|
CAVEY GERARD wrote: >Hi there > >Few days ago i switched to Visual c++ 6.0 and this is what i discovered. >The compiler accept the following C++ code : > >//first loop > for(unsigned long b=0;b<MeshesArray[current].VerticesCount;b++) > { > ...//processing > } >//second loop > for( b=0;b<not_used*3;b++) > { > ... > } > >But i thiink i should write the second FOR like this "for(unsigned long >b=0;b<not_used*3;b++)" (i mean i should redeclare 'b' because it came out of >scope) >When i tried the compiler answered me "error redefinition ..." !!! >Did i forget to set an option ;it is a bit strange isn t it? > >Greetings >GC > > The best way to avoid this bug in VC 6 is to put 'unsigned long b' before the first loop like this: unsigned long b; for (b = 0 ; ...) ... for (b = 0 ; ...) We had the same problem in Crystal Space. Greetings, |
From: <ke...@ac...> - 2004-02-04 12:27:57
|
The way I've worked around this in the past has been by redefining for as follows: #define for if (false) {} else for Yes, it's a hideously ugly hack, but so is the problem in the first place. I've never had any problems because of it. // Kristoffer From: "Jorrit Tyberghein" <Jor...@uz...> > CAVEY GERARD wrote: > > >Hi there > > > >Few days ago i switched to Visual c++ 6.0 and this is what i discovered. > >The compiler accept the following C++ code : > > > >//first loop > > for(unsigned long b=0;b<MeshesArray[current].VerticesCount;b++) > > { > > ...//processing > > } > >//second loop > > for( b=0;b<not_used*3;b++) > > { > > ... > > } > > > >But i thiink i should write the second FOR like this "for(unsigned long > >b=0;b<not_used*3;b++)" (i mean i should redeclare 'b' because it came out of > >scope) > >When i tried the compiler answered me "error redefinition ..." !!! > >Did i forget to set an option ;it is a bit strange isn t it? > > > >Greetings > >GC > > > > > > The best way to avoid this bug in VC 6 is to put 'unsigned long b' > before the first > loop like this: > > unsigned long b; > for (b = 0 ; ...) > ... > for (b = 0 ; ...) > > We had the same problem in Crystal Space. > > Greetings, > |
From: Jorrit T. <Jor...@uz...> - 2004-02-04 13:26:24
|
Kristoffer Grönlund wrote: >The way I've worked around this in the past has been by redefining for as >follows: >#define for if (false) {} else for > >Yes, it's a hideously ugly hack, but so is the problem in the first place. >I've never had any problems because of it. > > Hmm... sounds like an ugly solution for something that is more simply solved by just declaring the loop counter outside the for. Greetings, |
From: Jorrit T. <Jor...@uz...> - 2004-02-04 14:52:10
|
Javier Arevalo wrote: >When you have a large codebase in the "proper" style, and suddenly need to >use it in a non-compliant compiler (like VC6), a hack may be worth a >thousand changes. > > > True enough. Greetings, |