View previous topic :: View next topic |
Author |
Message |
soonc
Joined: 03 Dec 2013 Posts: 215
|
Variable name length |
Posted: Thu Sep 15, 2016 11:55 am |
|
|
CCS PCD C Compiler, Version 5.062, xxxxx
Is there a limit on the length of a variable name in source code ?
Example:
Code: |
// as a global int16 variable
int16 g_n16ThisIsALongVariableNameUsedForTestingOnly = 0;
|
My reason for asking is:
I have a situation where a long variable is not working.
Code: | g_n16AnotherVar = 345;
g_n16ThisIsALongVariableNameUsedForTestingOnly = (g_n16AnotherVar * 2);
|
g_n16ThisIsALongVariableNameUsedForTestingOnly value is Zero.
If I reduce the character length it works.
Code: | g_n16AnotherVar = 345;
g_n16LongVariableName = (g_n16AnotherVar * 2); |
g_n16LongVariableName display as expected 690.
The lst file has the same instructions for both statements ! |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Thu Sep 15, 2016 4:48 pm |
|
|
this is NOT hard to test.
Last edited by asmboy on Thu Sep 15, 2016 4:58 pm; edited 1 time in total |
|
|
soonc
Joined: 03 Dec 2013 Posts: 215
|
|
Posted: Thu Sep 15, 2016 4:53 pm |
|
|
asmboy wrote: | this is NOT hard to test.
and the LST file is your friend. |
Yes as I said the LST file produces the same code, but the variable remains at zero !
When I changed the variable name to something shorter it works....
I'd like to know if there is a limit to the length of a variable name. |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Thu Sep 15, 2016 4:54 pm |
|
|
Limit name to 31 chars or less.
Ditto function names and labels in general.
Stay under 32 and be happy.
and BTW #define is limited to 254 chars.
Last edited by asmboy on Thu Sep 15, 2016 5:05 pm; edited 2 times in total |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9218 Location: Greensville,Ontario
|
|
Posted: Thu Sep 15, 2016 4:55 pm |
|
|
Interesting, as I've never seen a 'keywords..do not use' list in the manual..
Those lists were in every BASIC book I used, long, long ago....
I can't type worth a damn, so I use short words, typically 3 letter groups (from ASM and COBOL days) that mean something when I program, then months latter...'What does this mean ??', sigh, old age is fun !!
Jay |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Sep 15, 2016 7:30 pm |
|
|
Quote: | I have a situation where a long variable is not working.
If I reduce the character length it works.
g_n16LongVariableName display as expected 690. |
I don't have the PCD compiler, so I compiled it in PCH vs. 5.062
and it worked. I got the following output in MPLAB vs. 8.92 simulator
in the SIM UART1 output window:
That's correct.
Test program:
Code: | #include <18F4620.h>
#fuses INTRC_IO,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4M)
#use rs232(baud=9600, UART1, ERRORS)
int16 g_n16AnotherVar = 345;
int16 g_n16ThisIsALongVariableNameUsedForTestingOnly = (g_n16AnotherVar * 2);
//======================================
void main(void)
{
printf("%lu %lu \r", g_n16AnotherVar, g_n16ThisIsALongVariableNameUsedForTestingOnly);
while(TRUE);
}
|
I also tested it using "signed int16" and "%ld" and got the same thing. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Sep 15, 2016 10:06 pm |
|
|
The July 2016 PCD Reference Manual says on page 40:
Quote: | Identifiers
ABCDE Up to 32 characters beginning with a non-numeric.
Valid characters are A-Z, 0-9 and _ (underscore). By
default not case sensitive Use #CASE to turn on. |
http://www.ccsinfo.com/downloads/PCDReferenceManual.pdf |
|
|
soonc
Joined: 03 Dec 2013 Posts: 215
|
Thanks to all for the responses |
Posted: Fri Sep 16, 2016 3:42 pm |
|
|
Age... Same issue for me....
I could comment each var declaration but the comment does not follow the var through many pages of code, and that's why I adopted long variable name which is really the comment, and so for many years I'm relied on that.
I think Visual Studio allows longer names, which is where I got spoiled I guess ! |
|
|
|