View previous topic :: View next topic |
Author |
Message |
DaveMorris
Joined: 13 Oct 2003 Posts: 6 Location: Stourbridge, England
|
Identifiers starting with numbers |
Posted: Sat Apr 09, 2022 4:26 am |
|
|
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
|
|
Posted: Sat Apr 09, 2022 7:16 am |
|
|
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
|
|
Posted: Sat Apr 09, 2022 10:05 am |
|
|
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. |
|
|
|