Problems assigning a CONSTANT to another CONSTANT

Previous topic - Next topic

Slydog

I have a library that I call from my main project module.
In this library, I set up some global constants.
Then, I tried to make another constant for a default value that assigns the value of one of the above constants, like this: (In Tween.gbas)
Code (glbasic) Select
CONSTANT kTweenTransition_Linear = 1
CONSTANT kTweenTransition_Spring = 2
CONSTANT kTweenTransition_Bounce = 3

CONSTANT kTweenTransition_Default = kTweenTransition_Spring


But, in my main module, when I refer to the constant that was assigned as default (kTweenTransition_Spring in this case), I get this C++ error:
error: `kTweenTransition_Spring' was not declared in this scope.

But when I assign a hard coded value like:
Code (glbasic) Select
CONSTANT kTweenTransition_Default = 2
everything works fine.

It seems assigning a constant to a constant causes the original constant to be declared earlier in the compiling cycle?

[edit]
Or never gets created in the first place? 
Or because it would have been created as a standard float in the first pass?
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Moru

I don't know if it is related but this sounds just like the declacaration of a variable and initializing it with another variable. A clear no-no :-)

Code (glbasic) Select

GLOBAL a = 5
GLOBAL b = a // might not work

GLOBAL b
b = a       // will always work

Quentin

hmmm for me it works without any error.

Code (glbasic) Select
CONSTANT kTweenTransition_Linear = 1
CONSTANT kTweenTransition_Spring = 2
CONSTANT kTweenTransition_Bounce = 3

CONSTANT kTweenTransition_Default = kTweenTransition_Spring


which version of GLBasic you're using?

bigsofty

I had a similar error but only when a constant was used in an external program, that is, not declared in the main program of a project.

Substituting GLOBALS works fine for now.

Cheers,


Ian
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

Slydog

I'm using GLBasic 7.341, demo.
I can recreate this using these 4 lines:

In main.gbas:
Code (glbasic) Select
LOCAL speed = kFast

And in library.gbas:
Code (glbasic) Select
CONSTANT kSlow = 1
CONSTANT kFast = 2
CONSTANT kSpeedDefault = kFast


This will trigger the compile error.
But if I simply change the main.gbas to:
Code (glbasic) Select
LOCAL speed = kSlow
everything compiles fine, because I'm not referring to the value assigned to kSpeedDefault.
If all of the above code is in the same module, I don't get any compile errors.

The work-around in this case is just to never use other constants as a default value for constants, but hard code them, as in:
Code (glbasic) Select
CONSTANT kSpeedDefault = 2

Thanks for your comments and suggestions.
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

MrTAToad

Its mainly due to variable definition rules - the secondary file isn't compiled before the main file...