Compiler or purifier improvement

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Compiler or purifier improvement

Post by Psychophanta »

There would be interesting if compiler or, at least the purifier warn when a constant is already declared:

Code: Select all

#er=45
#er=45
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Compiler or purifier improvement

Post by luis »

It would be a pain especially when you make some include with OS constants in it.
Sometimes they are in the PB residents already, sometimes they aren't.
What it isn't there today can be there tomorrow.
Now PB give an error when a constant is declared twice but with different values, and that's good.
When a constant is re-declared with the same value PB doesn't say anything and I think it's the best thing to do.
Even not considering residents, you can have the same constants defined in more includes.

You already guessed, I disagree.
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: Compiler or purifier improvement

Post by Psychophanta »

I see, however, what about the purifier?
And what about if there is re-declared a constant in a single file?
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Compiler or purifier improvement

Post by Fred »

The purifier is a runtime tool, it doesn't have this information.
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: Compiler or purifier improvement

Post by PMV »

The compiler already reports it.

Code: Select all

#er=45
#er=46
Only if it is the same ... some people could see that as a
feature. As long as the value is the same, it gets just ignored.
And i really can't think about a problem with that ... for me
it makes no difference.

MFG PMV
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: Compiler or purifier improvement

Post by Psychophanta »

Well, then imo, there would make things easier if there exist something that warn when a constant is declared twice (even with the same value) inside or outside a source file.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: Compiler or purifier improvement

Post by freak »

You can add a check if a constant already exists:

Code: Select all

CompilerIf Defined(SomeConst, #PB_Constant)
  CompilerError "Constant already defined"
CompilerEndIf

#SomeConst = 1
If you have this piece of code twice inside your program, the second one will create a compiler error.
quidquid Latine dictum sit altum videtur
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: Compiler or purifier improvement

Post by Tenaja »

Turn it into a macro (named, for instance, DefineSafe), and it will be convenient...
Post Reply