Page 1 of 1
Compiler or purifier improvement
Posted: Fri Dec 14, 2012 3:45 pm
by Psychophanta
There would be interesting if compiler or, at least the purifier warn when a constant is already declared:
Re: Compiler or purifier improvement
Posted: Fri Dec 14, 2012 4:06 pm
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.
Re: Compiler or purifier improvement
Posted: Fri Dec 14, 2012 4:10 pm
by Psychophanta
I see, however, what about the purifier?
And what about if there is re-declared a constant in a single file?
Re: Compiler or purifier improvement
Posted: Fri Dec 14, 2012 4:16 pm
by Fred
The purifier is a runtime tool, it doesn't have this information.
Re: Compiler or purifier improvement
Posted: Fri Dec 14, 2012 4:26 pm
by PMV
The compiler already reports it.
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
Re: Compiler or purifier improvement
Posted: Fri Dec 14, 2012 4:53 pm
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.
Re: Compiler or purifier improvement
Posted: Fri Dec 14, 2012 6:46 pm
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.
Re: Compiler or purifier improvement
Posted: Fri Dec 14, 2012 7:04 pm
by Tenaja
Turn it into a macro (named, for instance, DefineSafe), and it will be convenient...