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

Identifiers starting with numbers

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



Joined: 13 Oct 2003
Posts: 6
Location: Stourbridge, England

View user's profile Send private message Visit poster's website

Identifiers starting with numbers
PostPosted: Sat Apr 09, 2022 4:26 am     Reply with quote

Hi,
I have just taken out a years update on PCH compiler (last updated version was it v5.013 – 2013 so it was getting a bit out of date).

Anyway, at that time it allowed you to start identifiers with numbers. Unfortunately, I named some identifiers with device number (i.e. 18F26K22), which compiled under v5.013 but does not compile under v5.107.

These identifiers where used by compiler conditionals in some old code, which I would like not to change.

i.e.
Code:

#define 18F26K22 1 // selects 18F26K22 device
.
.
#if defined(18F26K22)
  // Code for the PIC18F26K22 insert here.
#end


I fully understand that strictly for C Language identifies should not start with a number (and now your compiler rightfully throws it out), but it there a compiler switch which allows numbers at start of the identifiers to be used.
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Sat Apr 09, 2022 7:16 am     Reply with quote

Hi,

This comes up from time to time, and I’ve never heard a compiler switch mentioned to turn off this behavior. The ‘standard’ method to handle this is to preface the variable name with an underscore (_) character. This preserves the ‘look’ of the variable and satisfies the compiler.

As a side note, I’m surprised this actually worked in an earlier v5 version, as this issues goes back way before that!

John
_________________
John

If it's worth doing, it's worth doing in real hardware!
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Sat Apr 09, 2022 10:05 am     Reply with quote

I must admit I'm amazed it ever worked with CCS. Certainly not after the
very earliest versions.
However 5.013, was still at the stage of the V5 compilers, where V5 was
still rather a beta, so possibly the syntax checking was faulty.
C specifically says:
A variable may not start with any numeric or special symbol except
underscore
and CCS has always been good at respecting C definitions.

Remember you could cheat and use a macro:

#define 18F26K22 _18F26K22

Which should make it work.
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