View previous topic :: View next topic |
Author |
Message |
hello188
Joined: 02 Jun 2010 Posts: 74
|
Maximum length for a name of a variable? |
Posted: Thu Sep 12, 2013 11:25 pm |
|
|
Hi. what is the maximum variable name length for CCS-C compiler??
anyone tried? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Fri Sep 13, 2013 5:23 am |
|
|
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
|
|
Posted: Fri Sep 13, 2013 6:28 am |
|
|
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? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Fri Sep 13, 2013 7:54 am |
|
|
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
|
|
Posted: Fri Sep 13, 2013 8:26 am |
|
|
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
|
Thank you |
Posted: Sun Sep 15, 2013 11:55 pm |
|
|
Thank you!! |
|
|
Depicci
Joined: 16 Sep 2013 Posts: 1 Location: Istanbul
|
Re: Maximum length for a name of a variable? |
Posted: Mon Sep 16, 2013 1:14 am |
|
|
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 |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Mon Sep 16, 2013 5:54 am |
|
|
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: 9226 Location: Greensville,Ontario
|
|
Posted: Mon Sep 16, 2013 6:19 am |
|
|
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: 19513
|
|
Posted: Mon Sep 16, 2013 7:25 am |
|
|
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 |
|
|
|