My intention is to output a list with offsets of all struct members from a typedef struct.

In my case this struct is stored in an external EEPROM which can be accessed bytewise via an interface accessible via a serial connection.

To access the EEPROM contents, I need to know the offsets of the struct members.

How can I tell the compiler to perform the offsetof task on every struct member?

有帮助吗?

解决方案

The C standard, and most C implementations, do not provide a way to automatically list the offsets of structure members or to iterate through structure members. You must either manually list the structure members or write your own software to parse the source code defining the structure (and to use the results of parsing to generate more code to display the offsets).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top