This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

anyone figured this one out

in a mixed environment I have a common .h which inlude things like
#ifdef CCODE
struct RALPH
#endif

so far so good.

now this, which, of course does not work:
#ifdef CCODE
struct RALPH
#endif
#define ralphsize sizeof (RALPH)

in other words, my assembler code need know the size of the structure (ralphsize) and the assembler can not handle structures in the .h

anyone have a trick beyond the obvious:
#define ralphsize 47 // sizeof (RALPH) make sure to change when


Erik

Parents
  • [IMHO, the unspecified toolset is actually fine for this question --- it doesn't really depend on any particular compiler.]

    There's no trick around the actual problem --- the C preprocessor has no knowledge of struct layout even when it's processing C code, much less if it's used on assembly source.

    But you can at least make sure that the number in #define ralphsize always matches the actual size of the struct. Just put an equivalent of

    assert(ralphsize == sizeof(struct RALPH));

    in some appropriate place of the C code (e.g. in the generic initialization function). For some nifty hacks how to implement compile-time assert()s, I suggest a look at the C FAQ.

Reply
  • [IMHO, the unspecified toolset is actually fine for this question --- it doesn't really depend on any particular compiler.]

    There's no trick around the actual problem --- the C preprocessor has no knowledge of struct layout even when it's processing C code, much less if it's used on assembly source.

    But you can at least make sure that the number in #define ralphsize always matches the actual size of the struct. Just put an equivalent of

    assert(ralphsize == sizeof(struct RALPH));

    in some appropriate place of the C code (e.g. in the generic initialization function). For some nifty hacks how to implement compile-time assert()s, I suggest a look at the C FAQ.

Children