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

symbol declaration, for an C structure element

If we define

struct _footype {
char c;
int x;
} foo;

foo would be a linkable symbol, being th aderess of real memory - of sizeof(struct _footype)

What can I do to declare a linkable symbol for x, the integer?

Parents
  • Just plain "int x;"?

    The point of the structure is to group related items. You would refer to x as "foo.x". Other modules referencing this data presumably understand the structure as well. In assembler, for example, you'd probably wind up defined a bunch of constants for the offsets of the fields in the structure.

    &foo.x gives you the address. There's also the offsetof() macro.

    I'm not really sure what your actual goal is here. I don't think you can get the linker to emit a symbol for "x", since there is no symbol x without foo.

Reply
  • Just plain "int x;"?

    The point of the structure is to group related items. You would refer to x as "foo.x". Other modules referencing this data presumably understand the structure as well. In assembler, for example, you'd probably wind up defined a bunch of constants for the offsets of the fields in the structure.

    &foo.x gives you the address. There's also the offsetof() macro.

    I'm not really sure what your actual goal is here. I don't think you can get the linker to emit a symbol for "x", since there is no symbol x without foo.

Children
No data