Gamestudio Links
Zorro Links
Newest Posts
Fun Arcade Car Physics (nfs style)
by Ezzett. 08/02/26 21:11
ZorroGPT
by TipmyPip. 07/31/26 22:56
Wolfram Mathematica with Zorro
by TipmyPip. 07/30/26 02:07
What are you working on?
by rayp. 07/24/26 22:58
Z9 getting Error 058
by madpower2000. 07/22/26 14:01
New Zorro version 3.11
by jcl. 07/21/26 13:42
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
0 registered members (), 2,779 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
riggi89, shuhari, KD1990, Ephraim, Student_64151
19223 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Redeclaration of local variables not caught #417266
02/11/13 02:41
02/11/13 02:41
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline OP
Expert
Uhrwerk  Offline OP
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Hello jcl,

the following code should be rejected with an error message but instead compiles and executes:
Code:
#include <acknex.h>

void main()
{
	int i = 0;
	int i = 0;
}



Best regards,
Uhrwerk


Always learn from history, to be sure you make the same mistakes again...
Re: Redeclaration of local variables not caught [Re: Uhrwerk] #417271
02/11/13 09:13
02/11/13 09:13
Joined: Jul 2000
Posts: 28,128
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,128
Frankfurt
Redeclaring variables is allowed in lite-C.

Re: Redeclaration of local variables not caught [Re: jcl] #417323
02/11/13 15:49
02/11/13 15:49
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline OP
Expert
Uhrwerk  Offline OP
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Ok. I didn't find this case specified in the C Reference Manual. So I tried some other compilers and they all gave an error message similar to "error: redeclaration of 'i'". What's the purpose of redeclaring local variables?


Always learn from history, to be sure you make the same mistakes again...
Re: Redeclaration of local variables not caught [Re: Uhrwerk] #417335
02/11/13 17:25
02/11/13 17:25
Joined: Dec 2008
Posts: 1,218
Germany
Rackscha Offline
Serious User
Rackscha  Offline
Serious User

Joined: Dec 2008
Posts: 1,218
Germany
oh, redeclaring is allowerd and mostly results in this spaghetie source:

Code:
for(int i = 0; i < 10; i++)
{
  for(int i = 0; i < 100; i++)
  {
    dosomethingwithint(i);
  }
}



I hate nested loops with redeclared vars ARGH -.-

Last edited by Rackscha; 02/11/13 17:25.

MY Website with news of my projects:
(for example my current
Muliplayer Bomberman,
GenesisPrecompiler for LiteC
and TileMaster, an easy to use Tile editor)
Sparetime-Development

Re: Redeclaration of local variables not caught [Re: Rackscha] #417336
02/11/13 17:28
02/11/13 17:28
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline OP
Expert
Uhrwerk  Offline OP
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
That's a different example. In your code snippet two variables with identical name are declared as well, but they have got a different scope.


Always learn from history, to be sure you make the same mistakes again...
Re: Redeclaration of local variables not caught [Re: Uhrwerk] #417342
02/11/13 19:35
02/11/13 19:35
Joined: Dec 2008
Posts: 1,218
Germany
Rackscha Offline
Serious User
Rackscha  Offline
Serious User

Joined: Dec 2008
Posts: 1,218
Germany
@Uhrwerk: yes they have different scopse, nontheless:
Redeclaring the same identifier over and over again just starts to confuse other people when reading the source tongue


MY Website with news of my projects:
(for example my current
Muliplayer Bomberman,
GenesisPrecompiler for LiteC
and TileMaster, an easy to use Tile editor)
Sparetime-Development

Re: Redeclaration of local variables not caught [Re: Rackscha] #417351
02/11/13 20:37
02/11/13 20:37
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline OP
Expert
Uhrwerk  Offline OP
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
I absolutely agree. Nevertheless this is not related to the original topic.


Always learn from history, to be sure you make the same mistakes again...
Re: Redeclaration of local variables not caught [Re: Uhrwerk] #417400
02/12/13 10:52
02/12/13 10:52
Joined: Jul 2000
Posts: 28,128
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,128
Frankfurt
The templates make heavy use of redeclaring variables.


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1