DEFINE_CONSTANT CHAR[] in HEX
mhermanns
Posts: 32
Dear Godfathers of AMX!
How can i define a CHAR[] constant with hex characters?
What i want is:
DEFINE_CONSTANT
CHAR MY_CONSTANT[3] = " $02 , $03 , $0D "
I do it like:
DEFINE_VARIABLE
CHAR MY_CONSTANT[3]
DEFINE_START
MY_CONSTANT = "$02,$03,$0D"
But there MUST be a more elegant way!?
So how can i define a CHAR[] constant with HEX characters directly in the DEFINE_CONSTANT section?
How can i define a CHAR[] constant with hex characters?
What i want is:
DEFINE_CONSTANT
CHAR MY_CONSTANT[3] = " $02 , $03 , $0D "
I do it like:
DEFINE_VARIABLE
CHAR MY_CONSTANT[3]
DEFINE_START
MY_CONSTANT = "$02,$03,$0D"
But there MUST be a more elegant way!?
So how can i define a CHAR[] constant with HEX characters directly in the DEFINE_CONSTANT section?
0
Comments
DEFINE_CONSTANT
CHAR MY_CONSTANT[3] = {$02,$03,$0D}
or skip the bounds and do it like this:
DEFINE_CONSTANT
CHAR MY_CONSTANT[] = {$02,$03,$0D}
Hi Joe!
And ones again: thank you!
e.g. 'PON',$0D,$0A
Another example (Integra CDC-3.4)
In case of doubt:
this is exactly what i was looking for!
BTW - What kind of error are you getting? The TOO MANY ELEMENTS IN INITIALIZER error or a different one. You would need to increase your size to 9 for your example.
Why do i need an array of size 9? Actually i have just 4 characters??
The error is because of the double quotes; not needed when initializing, only if assigning a value to a variable, which you can't do here anyway becvause it's a CONSTANT. CHAR { 'P', 'O', 'N', $0D } does it. Lumping the PON together in a single quote provokes a string-to-CHAR warning, but I think it is benign - I just hate to leave compiler warnings unheeded. There is also no need to put a value in the square brackets, it sizes according to the initializer, and since it's a CONSTANT, never changes.
In the good 'ol Axcess days you could write:
DEFINE_CONSTANT
PROJ_ON = "'PON' $0D"
very readable and consistent with the way you build strings elsewhere.
but this feature wasn't carried through to Netlinx, which made upgrading Axcess code to netlinx real fun, not to mention writing device drivers that work on both platforms.
AMX told me the original capability of having non-printable chars in a constant string was "a mistake", so it was removed in the upgrade. The options in Netlinx are the unreadable: string of chars inside curly braces { 'P', 'O', 'N', $0D } or the illogical: use constant variables (a contradiction in terms by any measure).
I prefer to declare the strings as variables, using capitals, and initialize them in DEFINE_START. By convention in C, things in capitals are constants and never appear to the left of the assignment operator (=)
IMHO the Axcess version was much better, and I wish they'd kept it.