zlack
zlack

Reputation: 2027

elements of a structure

Is there a way to get all the elements of a structure, so I can use them and perhaps iterate over them and print them ?

Upvotes: 1

Views: 176

Answers (3)

philant
philant

Reputation: 35856

This is possible with X-macros. See this answer where I demonstrate exactly this.

Upvotes: 2

Pierre Bourdon
Pierre Bourdon

Reputation: 10890

C does not provide a standard way to do this. However, you may be able to hack something using the C preprocessor and the offsetof GNU C extension.

Upvotes: 0

jldupont
jldupont

Reputation: 96854

There isn't any reflexion in C: you'll have to "fake" one.

Upvotes: 1

Related Questions