Android Question Constants before declaration

davemorris

Active Member
Licensed User
Longtime User
Hi Guys
Having an issue about constants used before declaration - l looking at the forum, I found a bug report from 2015
https://www.b4x.com/android/forum/t...onstants-referenced-before-declaration.54185/
describing a similar problem (mine is in a code module and I have used publics).

My question is
Is this is a bug or not - or has it returned.
My general experience with modern compilers, is the order of declaration is normally not important, should this be the case with B4A?

Kind regards
Dave
 

davemorris

Active Member
Licensed User
Longtime User
Hi, Thanks for the response
Question did you read the original bug - it does sum-up the problem
However, in my case I created a code module (lets called it myModule)
B4X:
Sub Process_Globals

Public constant X1 as string = "First  string" &  X2

Public constant X2 as string = "Second string"

Public constant X3 as string = X1 & X2

Then a separate class/activity used these constants (lets call it myClass).
B4X:
Private xxx as string = myModule.X1 ' xxx = "First string" ' **** the second half is missing (X2 defined after X1)

Private yyy as string = myModule.X3 ' yyy = "First stringSecond string" ' ** X3 was defined after X2 therefore it is correct!

As you can see the order of definition appears to by important for B4A.

Having said all that, I may have made a error in my code and have to "eat my works!"

Kind regards
Dave
 
Upvote 0

davemorris

Active Member
Licensed User
Longtime User
Hi Erel
OK I accept you have chosen to make the order of constant declaration important (although it don't appear to matter with subroutines).

But, not reporting a problem is bad as the programmer is unaware of the situation.
In my case I simply decided to rearrange some public constants in a code module into alphabetical order. Then when I ran a test on the software, it simply malfunctioned - very easy to trace the problem.

However without a warning, this type of issue could cause hidden hard to find faults.

Kind regards
Dave
 
Upvote 0
Top