Constant Declaration
cbailey
Junior Member
I am confused by how the Netlinx compiler interprets the following code for constant declaration:
I would also expect that const ACCEPT would evaluate to a string of length 3 with the value = OK,$0D.
This is not the case. Through the debug window it appears that ACCEPT has length 14 with value = 'OK',DELIMITER (NOTE: both the single quotes and comma are part of the value of ACCEPT).
Does anyone have some insight as to why the compilier interprets this code in this way?
DEFINE_CONSTANT CONSTANT CHAR DELIMITER = $0D; CONSTANT CHAR ACCEPT[] = "'OK',DELIMITER";I would expect that const DELIMITER would evaluate to a char with value = 13 (or $0D in ascii).
I would also expect that const ACCEPT would evaluate to a string of length 3 with the value = OK,$0D.
This is not the case. Through the debug window it appears that ACCEPT has length 14 with value = 'OK',DELIMITER (NOTE: both the single quotes and comma are part of the value of ACCEPT).
Does anyone have some insight as to why the compilier interprets this code in this way?
Comments
-
The rules for declaring string constants are kinda whacky in Netlinx. Your best bet is to check out Tech Note 531 on AMX's website, which goes into it in great detail.
Basically, you can't use double quotes in constant delcarations, so that's probably messing up your efforts the most.
- Chip -
Thanks Chip!
That tech note does explain quite a bit on the subject. I guess I shouldn't just assume that the standards of Netlinx code carry over from one section of the code to the next.
For future reference, here's the updated code that behaves properly:DEFINE_CONSTANT CONSTANT CHAR DELIMITER = $0D; CONSTANT CHAR ACCEPT[] = {'O','K',DELIMITER}; -
Just as an aside, the CONSTANT CHAR is redundant in the DEFINE_CONSTANT section. You don't need it there, only if you were declaring them in DEFINE_VARIABLE (not sure why you would).
-
You're right, it wouldn't make any sense to declare constants in the variable section, but it is supported for some reason. I put CONSTANT and CHAR in front of my declarations out of habit from prior programming experiences, guess I just can't break myself of it.DHawthorne wrote:Just as an aside, the CONSTANT CHAR is redundant in the DEFINE_CONSTANT section. You don't need it there, only if you were declaring them in DEFINE_VARIABLE (not sure why you would).
-
For what it's worth, I occasionally put constants in DEFINE_VARIBLE, next to other variables that reference them. Sometimes it's nice to have everything together to help keep it all in context.
--D -
Good ideadchristo wrote:For what it's worth, I occasionally put constants in DEFINE_VARIBLE, next to other variables that reference them. Sometimes it's nice to have everything together to help keep it all in context.
--D
I do the same, especially when declaring multiple Define_Variable sections that can be managed with code folding.
Categories
- All Categories
- 2.5K AMX General Discussion
- 922 AMX Technical Discussion
- 514 AMX Hardware
- 502 AMX Control Products
- 3 AMX Video Distribution Products
- 9 AMX Networked AV (SVSI) Products
- AMX Workspace & Collaboration Products
- 3.4K AMX Software
- 151 AMX Resource Management Suite Software
- 386 AMX Design Tools
- 2.4K NetLinx Studio
- 135 Duet/Cafe Duet
- 248 NetLinx Modules & Duet Modules
- 57 AMX RPM Forum
- 228 MODPEDIA - The Public Repository of Modules for Everyone
- 943 AMX Specialty Forums
- 2.6K AMXForums Archive
- 2.6K AMXForums Archive Threads
- 1.5K AMX Hardware
- 432 AMX Applications and Solutions
- 249 Residential Forum
- 182 Tips and Tricks
- 146 AMX Website/Forums