View previous topic :: View next topic |
Author |
Message |
kda406
Joined: 17 Sep 2003 Posts: 97 Location: Atlanta, GA, USA
|
sizeof() Broken in 4.10x? |
Posted: Thu Apr 22, 2010 11:15 am |
|
|
I am using a PIC18F8722. The following code segment has compiled from 2.x until 4.093. In 4.104 it no longer compiles. I tried 4.106 and it does not compile using that version either. I went back to 4.093 and it compiles with no problem. I have reviewed the compiler updates and cannot find any reference to code depreciation that would affect this. Here is the code:
Code: | ////// Global Structures //////
struct rtcdatamem { // Structure of the RTC data memory
int8 vermajor; // Slave software major version (read only)
int8 verminor; // Slave software minor version (read only)
int16 vdd; // System VDD voltage (read only)
int8 eepromupdate; // EEPROM update flag
int8 freq; // Frequency of line power coming in
int8 duty; // Percent of duty cycle (whole number 0-100)
int32 ssm; // Elapsed time (Seconds) Since Millenium
int8 scratch[64]; // "Scratch Pad" backed up RAM
};
struct rtcbytemem {
char loc[sizeof(rtcdatamem)]; // Bytes of shared memory
};
union rtcmemunion {
struct rtcdatamem value; // Memory as data units
struct rtcbytemem discrete; // Discrete memory locations
} RTCMem; | Which creates the following errors (line 74 is the char loc[sizeof... line in the second struct): Quote: | *** Error 12 "C:\Devel\PIC-C\Devices\Dev-GCRTCMaster.c" Line 74(17,27): Undefined identifier rtcdatamem
*** Error 43 "C:\Devel\PIC-C\Devices\Dev-GCRTCMaster.c" Line 74(28,29): Expecting a declaration
*** Error 43 "C:\Devel\PIC-C\Devices\Dev-GCRTCMaster.c" Line 74(29,30): Expecting a declaration
*** Error 43 "C:\Devel\PIC-C\Devices\Dev-GCRTCMaster.c" Line 75(1,2): Expecting a declaration
*** Error 43 "C:\Devel\PIC-C\Devices\Dev-GCRTCMaster.c" Line 75(2,3): Expecting a declaration | Have I had this wrong for years, or is the compiler broken?
Thanks,
Kyle |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Apr 22, 2010 11:54 am |
|
|
I was able to make it compile by telling the compiler that rtcdatamem
is a structure, by adding the 'struct' keyword shown below. This was
tested with vs. 4.106:
Quote: | struct rtcdatamem { // Structure of the RTC data memory
int8 vermajor; // Slave software major version (read only)
int8 verminor; // Slave software minor version (read only)
int16 vdd; // System VDD voltage (read only)
int8 eepromupdate; // EEPROM update flag
int8 freq; // Frequency of line power coming in
int8 duty; // Percent of duty cycle (whole number 0-100)
int32 ssm; // Elapsed time (Seconds) Since Millenium
int8 scratch[64]; // "Scratch Pad" backed up RAM
};
struct rtcbytemem {
char loc[sizeof(struct rtcdatamem)]; // Bytes of shared memory
};
union rtcmemunion {
struct rtcdatamem value; // Memory as data units
struct rtcbytemem discrete; // Discrete memory locations
} RTCMem; |
|
|
![](templates/subSilver/images/spacer.gif) |
kda406
Joined: 17 Sep 2003 Posts: 97 Location: Atlanta, GA, USA
|
|
Posted: Thu Apr 22, 2010 12:04 pm |
|
|
Thanks very much. That fixes it.
It feels like a step backward...I wonder why they changed this.
Thanks,
Kyle |
|
![](templates/subSilver/images/spacer.gif) |
dyeatman
Joined: 06 Sep 2003 Posts: 1924 Location: Norman, OK
|
|
Posted: Thu Apr 22, 2010 12:21 pm |
|
|
This seems to be motivated by a change in the ANSI/IEEE standards due to
data alignment considerations. So it looks like CCS is moving closer to ANSI
compliance... _________________ Google and Forum Search are some of your best tools!!!! |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Apr 22, 2010 12:34 pm |
|
|
I think it's part of the C specification. If a structure tag (name) is used
in a declaration, then you need to put the 'struct' keyword in front of it.
For example, if I compile your test program as a .C file in MSVC++ 6.0,
I get this error:
(I first changed all the int8, int16, etc., data types to compatible C types).
Quote: |
Error C2065: 'rtcdatamem' : undeclared identifier
Error executing cl.exe.
|
If I add the 'struct' keyword then it compiles.
I don't run into this problem because I typedef all my structures.
Then I can reference them without using the 'struct' keyword.
What I think is happening, is that CCS is quietly making their compiler
more 'correct'. They're just not announcing it in the list of version
changes. |
|
![](templates/subSilver/images/spacer.gif) |
|