Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (degenerate_762, AndrewAMD), 877 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 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: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

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

Chief Engineer
jcl  Offline

Chief Engineer

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


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

Gamestudio download | chip programmers | 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