Constant or function already defined warning not given!

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Constant or function already defined warning not given!

Post by Rescator »

Not really sure if this is a bug or deliberate design decision but...

Shouldn't the compiler react to this?:

Code: Select all

#S_OK=0
It is already defined as can be seen here:

Code: Select all

x=#S_OK

#S_OK=0
Trying

Code: Select all

#S_OK=2
gives an expected reaction.

I'm not saying the current way is wrong, I'd just like some warning or notification so I can get rid of a whole bunch of unneeded constant defines. (over time as constants are added to PB, old sources tend to get redundant constant defines obviously)

Maybe the compiler could do redundancy warnings if EnableExplicit is used?

*scratches head*

Structures, Interfaces, and Prototypes on the other hand seems to have these checks.

But functions are worse off, like this example:

Code: Select all

MessageBox_(#Null,"Test","Hmm!",#Null)

Procedure MessageBox_(text$,title$)
 Debug "Now this is just silly! And potentially dangerous!"
 Debug title$+" "+text$
EndProcedure

MessageBox_("Test2","Oops?")
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Constant or function already defined warning not given!

Post by PB »

It only gives a warning if the new value is different to the existing value.
I think I read it was done that way, so that if you copy and paste code from
here into the editor, you don't need to manually remove any constants just
to run the code.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Post by Rescator »

I can understand that reasoning, but it's still a major issue with predefined stuff like this.

Whether the coder makes double definitions in their own code is a different matter. :)

Besides! I said warning not error, a warning would still allow compilation,
it would just spit out a message that it was already defined or a possible conflict.

So maybe tying this into EnableExplicit would be best for all parties then?

I wouldn't mind at all if the compiler spat out a warning during compilation that I'm a moron for not remembering I already defined a constant or procedure in an include previously. ;)
Post Reply