Page 1 of 1

Constant or function already defined warning not given!

Posted: Sat Jul 25, 2009 5:32 am
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?")

Re: Constant or function already defined warning not given!

Posted: Sat Jul 25, 2009 6:29 am
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.

Posted: Sat Jul 25, 2009 7:17 am
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. ;)