avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] Paste structure tokens with the preprocessor ##?


From: Bob Paddock
Subject: [avr-gcc-list] Paste structure tokens with the preprocessor ##?
Date: Thu, 08 Nov 2007 12:11:34 -0500
User-agent: Opera Mail/9.10 (Win32)


Is it valid to paste structure tokens with
the preprocessor ## operator?

I get one of two errors,
depending on if I do "X.##M" or "X##M":

'error: pasting "." and "Accel_mo_setting_x_u16"
does not give a valid preprocessing token.'
What happend to the text before the dot?

or

'EE_PROM' has no member named
'factory_settings0Accel_mo_setting_x_u16'
Which is true because there is no dot.


I hope this code snippet will explain
my question better:

#include <eeprom.h>
#include <stddef.h> /* Include offsetof() */

typedef struct
{
  uint16_t  Accel_mo_setting_x_u16;

uint16_t crc_u16; /* CRC value of this EEPROM structure, this must be last in the structure */
}EE_PROM_FACTORY_SETTINGS;

typedef struct /* Physical EEPROM layout: */
{
  uint16_t not_used_u16;

  EE_PROM_FACTORY_SETTINGS factory_settings0;
  EE_PROM_FACTORY_SETTINGS factory_settings1;
}EE_PROM;

#define SIZEOF(s,m) ((size_t) sizeof(((s *)0)->m))/* Return the size of a member of a structure in offsetof() style */

#define EE_FACTORY_RD(M,D) eeprom_read_block(D, (const void *) offsetof(EE_PROM,factory_settings0.##M), SIZEOF(EE_PROM,factory_settings0.##M))

Usage example:

EE_FACTORY_WR( Accel_mo_setting_x_u16, address );

which returns:

'error: pasting "." and "Accel_mo_setting_x_u16"
does not give a valid preprocessing token.'

or

'EE_PROM' has no member named
'factory_settings0Accel_mo_setting_x_u16'

depending on the presence or absence of the
structure dot operator in the macro.

?





reply via email to

[Prev in Thread] Current Thread [Next in Thread]