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

Expecting a structure/union error

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



Joined: 07 Jul 2009
Posts: 98
Location: Curtea de Arges, Romania

View user's profile Send private message Send e-mail Yahoo Messenger

Expecting a structure/union error
PostPosted: Thu Sep 10, 2015 1:05 pm     Reply with quote

I try to search 1 day for this error but without result, in PICs manual don't explain about this. The structure looks like that
Code:

typedef union {
  unsigned int16 u16;               // element specifier for accessing whole u16
  signed int16 i16;                 // element specifier for accessing whole i16
  struct {
    unsigned int8 u8L;              // element specifier for accessing low u8
    unsigned int8 u8H;              // element specifier for accessing high u8
  } s16;                  // element spec. for acc. struct with low or high u8
} nt16;


or like that
Code:
typedef union {
         union{
  unsigned int16 u16;               // element specifier for accessing whole u16
  signed int16 i16;                 // element specifier for accessing whole i16
  struct {
    unsigned int8 u8L;              // element specifier for accessing low u8
    unsigned int8 u8H;              // element specifier for accessing high u8
   } s16;                  // element spec. for acc. struct with low or high u8
  };
} nt16;


or like that
Code:
typedef union {
         union{
  unsigned int16 u16;               // element specifier for accessing whole u16
  signed int16 i16;                 // element specifier for accessing whole i16
  struct {
    unsigned int8 u8L;              // element specifier for accessing low u8
    unsigned int8 u8H;              // element specifier for accessing high u8
   } s16;                  // element spec. for acc. struct with low or high u8
  };
} nt16__;
  nt16__     nt16;


and the function that access this structure
Code:

  pMeasurand->s16.u8H = data[0] = I2c_ReadByte(0);
  pMeasurand->s16.u8L = data[1] = I2c_ReadByte(0);

Can everyone say me what i am do wrong ? If need i can post entire function, the controller is 18f4550 Embarassed
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Sep 10, 2015 7:34 pm     Reply with quote

Your code doesn't even compile. It gives the "unidentified identifier" error
for this: pMeasurand

Post a test program. And post your compiler version.
wangine



Joined: 07 Jul 2009
Posts: 98
Location: Curtea de Arges, Romania

View user's profile Send private message Send e-mail Yahoo Messenger

PostPosted: Fri Sep 11, 2015 7:45 am     Reply with quote

Has my mistake, too late, tired and frustrated i put one letter more,
Code:
typedef union {
  unsigned int16 u16;               // element specifier for accessing whole u16
  signed int16 i16;               // element specifier for accessing whole i16
  struct {
    unsigned int8 u8L;              // element specifier for accessing low u8
    unsigned int8 u8H;              // element specifier for accessing high u8
  } s16;                  // element spec. for acc. struct with low or high u8
} nt16;

and code who acces that
Code:

//===========================================================================
int8 SHT2x_MeasureHM(etSHT2xMeasureType eSHT2xMeasureType, nt16 *pMeasurand)
//===========================================================================
{
  int8  checksum;   //checksum
  int8  data[2];    //data array for checksum verification
  int8  error=0;    //error variable
  int16 i;          //counting variable

  //-- write I2C sensor address and command --
  I2c_StartCondition();
  error |= I2c_WriteByte (I2C_ADR_W); // I2C Adr
  switch(eSHT2xMeasureType)
  { case HUMIDITY: error |= I2c_WriteByte (TRIG_RH_MEASUREMENT_HM); break;
    case TEMP    : error |= I2c_WriteByte (TRIG_T_MEASUREMENT_HM);  break;
    default: break;
 //   default: assert(0);
  }
  //-- wait until hold master is released --
  I2c_StartCondition();
  error |= I2c_WriteByte (I2C_ADR_R);
  output_float(scl_pin);                     // set SCL I/O port as input
  for(i=0; i<1000; i++)         // wait until master hold is released or
  { DelayMicroSeconds(1000);    // a timeout (~1s) is reached
    if (input_state(scl_pin) == true) break;
  }
  //-- check for timeout --
  if(input_state(scl_pin)==false) error |= TIME_OUT_ERROR;

  //-- read two data bytes and one checksum byte --
  pMeasurand->s16.u8H = data[0] = I2c_ReadByte(ACK);
  pMeasurand->s16.u8L = data[1] = I2c_ReadByte(ACK);
  checksum=I2c_ReadByte(NO_ACK);

  //-- verify checksum --
  error |= SHT2x_CheckCrc (data,2,checksum);
  I2c_StopCondition();
  return error;
}

my mistake was here
Code:
int8 SHT2x_MeasureHM(etSHT2xMeasureType eSHT2xMeasureType, int16 *pMeasurand)

i put in mistake int16 insted of nt16
Code:
int8 SHT2x_MeasureHM(etSHT2xMeasureType eSHT2xMeasureType, nt16 *pMeasurand)

Is strange error, normal was a syntax error but the compiler know the int16 and return other error. Thanks
jeremiah



Joined: 20 Jul 2010
Posts: 1355

View user's profile Send private message

PostPosted: Fri Sep 11, 2015 9:00 am     Reply with quote

That would make sense. It is a normal error. Your function prototype indicated a pointer to an int16, so when you used the -> operator on it, it flagged it as an error as you would only do that with a struct or union pointer, not an int16 pointer. Remember, the compiler wouldn't know you intended have a struct or a union until you try to use it as one. Up until that point, it thinks you are using an int16. It can't see into the future unfortunately.
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