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

Structs within structs

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



Joined: 13 Nov 2012
Posts: 219
Location: France

View user's profile Send private message

Structs within structs
PostPosted: Thu Aug 14, 2014 7:37 am     Reply with quote

I have something like this ( I can't post the whole code because it's sensitive and v.big)

Code:
typedef struct calibration
{
   float x0;
   float y0;
   float gain;
   float offset;
};

typedef struct axis
{
   float full_scale_range;   
   float scale_factor;
};

typedef struct
{
   struct axis x;
   struct axis y;
   struct calibration calpts;
   float  range;                 
   float  K; 
   float  x_raw;
   float  y_raw;
}sensor;

sensor elevation;


and it compiles and works fine in the normal way, but when I use it as a bootloaded application, it fails at run time. Some of the values from the calibration struct read wrong.

I've searched for anything here on structs like this, but no luck.

Is this code acceptable in CCS?

PIC18F
compiler 5.026
Ttelmah



Joined: 11 Mar 2010
Posts: 19551

View user's profile Send private message

PostPosted: Thu Aug 14, 2014 9:13 am     Reply with quote

Your syntax is slightly dubious.. You use, then don't use a typedef:
Code:

typedef struct calibration
{
   float x0;
   float y0;
   float gain;
   float offset;
} calibration_t;

typedef struct axis
{
   float full_scale_range;   
   float scale_factor;
} axis_t;

typedef struct
{
   axis_t x;
   axis_t y;
   calibration_t calpts;
   float  range;                 
   float  K;
   float  x_raw;
   float  y_raw;
} sensor_t;

sensor_t elevation;   


You are declaring a typedef, which then expects a name, but don't give it a name, instead you give the structure a name, and omit the typedef name. So you then don't actually use the typedef.

Either do the typedefs as I show, or get rid of the typedef declaration, and just use the structure name. Note the use of _t, to show the typedef declarations (useful reminder...).

Now, using the typedef, without a name, might well cause the compiler to be doing something 'wrong', so might be your problem. It's _possible_ that this results in both typedefs having the same 'blank' name (low compiler trust mode....). Note how the structure name is optional, but the typedef name should be there (shown on the sensor_t declaration).
However in general, CCS is 'known' for sometimes having issues as types get more complex (generally though with things like arrays of structures inside a structure). However (that having been said), this is not overly complex, and appears to work perfectly in everything I try.

This should be acceptable.

How is the value actually used in the application?. Is it local, or a global?. const?. Realistically, if it works on a 'raw' compile, but not when built for use as a bootloaded application, then look at what is different when the code is bootloaded. Obviously less ROM. Interrupt re-vectoring. Where does the data come from?. EEPROM?. Are you sure the bootloader is working completely correctly? (something like some bytes being corrupted where a particular ROM page boundary is crossed, could cause unexpected errors). What happens if you build the code as normal, but use #ORG to force the actual routines to load in the same location as when you build for the bootloader?. Are you sure the bootloader isn't doing something like corrupting a ram area?.
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