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

Maximum length for a name of a variable?

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



Joined: 02 Jun 2010
Posts: 74

View user's profile Send private message

Maximum length for a name of a variable?
PostPosted: Thu Sep 12, 2013 11:25 pm     Reply with quote

Hi. what is the maximum variable name length for CCS-C compiler??

anyone tried?
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Sep 13, 2013 5:23 am     Reply with quote

I'd _think_ ,_maybe_ 255, though you should try it yourself and report back.
Frankly, I use SHORT names as they're easier to type, easier to read, and easier to retype when I misspell them ! Then again, I grew up on a BASIC that only allowed 2 character variables.....ah, the 'good old dayze'.

jay
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Fri Sep 13, 2013 6:28 am     Reply with quote

I've never had the compiler complain about var_len.
And there is such an easy way to find out.

Have you tried it ?

Or put another way, are you an experimenter or not? Very Happy Very Happy Very Happy
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Sep 13, 2013 7:54 am     Reply with quote

Well you can tell I'm bored..cool,rainy,blaaa day here..

Did a simple test creating a char variable 26 characters long(every letter of the alphabet) and it was fine,kept doubling the length to 16 alphabets = 416 characters long..
..compiles just fine...

Sure wouldn't want to find a 'typo' in the variable name though!!


Jay
alan



Joined: 12 Nov 2012
Posts: 357
Location: South Africa

View user's profile Send private message

PostPosted: Fri Sep 13, 2013 8:26 am     Reply with quote

Maybe so, but the compiler only recognise the 1st 64 character. If your name is longer than that you can mispell or just leave it out.

Regards
hello188



Joined: 02 Jun 2010
Posts: 74

View user's profile Send private message

Thank you
PostPosted: Sun Sep 15, 2013 11:55 pm     Reply with quote

Thank you!!
Depicci



Joined: 16 Sep 2013
Posts: 1
Location: Istanbul

View user's profile Send private message Send e-mail

Re: Maximum length for a name of a variable?
PostPosted: Mon Sep 16, 2013 1:14 am     Reply with quote

You can try it if you have an output device or rs232 connection.
Create two variables for test
whatkindofsorceryisthis = '1'
whatkindofsorceryisthis2 = '2'
printf whatkindofsorceryisthis
if everything is ok extend variable name letter by letter and test it. The second variable should be different 'but just one letter' from the first one. When you obtain '2' as output, stop and count Smile
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Mon Sep 16, 2013 5:54 am     Reply with quote

A BASIC compiler I used 35 years ago used the first six characters and the length of the variable name. It would have recognized whatkindofsorceryisthis2 as longer than whatkindofsorceryisthis.
_________________
The search for better is endless. Instead simply find very good and get the job done.
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Sep 16, 2013 6:19 am     Reply with quote

You can tell I don't want to do real work....
...this works fine....

//global variables
24: char qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnm=1;
25: char qqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnm=2;

from the listing....
jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Mon Sep 16, 2013 7:25 am     Reply with quote

The change needs to be at the _right end_ of the variable. Comparisons are done left to right.

Code:

   char qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopaa=1;
   char qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopab=2;

//Builds OK

   char qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasa=1;
   char qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasb=2;

//doesn't

64 significant characters, as Alan says.

Worth also adding that this is 'per section' of the full variable name. So if you have a structure, there are 64 characters significant in the structure name, and then another 64 in the individual variables in the structure. Given that it is expansion of things like structures that is really likely to lead to OTT 'long names', it makes it very unlikely that it is ever going to cause a problem in use.

Best Wishes
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