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

sizeof() Broken in 4.10x?

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



Joined: 17 Sep 2003
Posts: 97
Location: Atlanta, GA, USA

View user's profile Send private message

sizeof() Broken in 4.10x?
PostPosted: Thu Apr 22, 2010 11:15 am     Reply with quote

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
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Apr 22, 2010 11:54 am     Reply with quote

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;
kda406



Joined: 17 Sep 2003
Posts: 97
Location: Atlanta, GA, USA

View user's profile Send private message

PostPosted: Thu Apr 22, 2010 12:04 pm     Reply with quote

Thanks very much. That fixes it.

It feels like a step backward...I wonder why they changed this.

Thanks,
Kyle
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Thu Apr 22, 2010 12:21 pm     Reply with quote

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!!!!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Apr 22, 2010 12:34 pm     Reply with quote

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.
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