CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Variable name length

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
soonc



Joined: 03 Dec 2013
Posts: 215

View user's profile Send private message

Variable name length
PostPosted: Thu Sep 15, 2016 11:55 am     Reply with quote

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

View user's profile Send private message AIM Address

PostPosted: Thu Sep 15, 2016 4:48 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Sep 15, 2016 4:53 pm     Reply with quote

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

View user's profile Send private message AIM Address

PostPosted: Thu Sep 15, 2016 4:54 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Sep 15, 2016 4:55 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Sep 15, 2016 7:30 pm     Reply with quote

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:
Quote:

345 690

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

View user's profile Send private message

PostPosted: Thu Sep 15, 2016 10:06 pm     Reply with quote

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

View user's profile Send private message

Thanks to all for the responses
PostPosted: Fri Sep 16, 2016 3:42 pm     Reply with quote

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 !
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group