Gamestudio Links
Zorro Links
Newest Posts
What are you working on?
by rayp. 11/02/26 13:57
No connection to MT4
by JeyKey II. 10/29/26 09:34
Zorro plugin for Hyperliquid.xyz
by opm. 10/28/26 13:50
Icon "OP"
by JeyKey II. 10/27/26 07:03
ZorroGPT
by TipmyPip. 10/26/26 08:09
Chat Room for Zorro Programmers
by Haitao_Ren. 10/25/26 03:14
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
2 registered members (AndrewAMD, TipmyPip), 11,680 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
MaliceTheMaker, Haitao_Ren, JimSimons, julienp, julienper
19248 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,145
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,145
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,145
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,145
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