Iterating over same type struct members in C

后端 未结 7 586
醉酒成梦
醉酒成梦 2020-12-10 20:06

Is it possible to iterate of a C struct, where all members are of same type, using a pointer. Here\'s some sample code that does not compile:

#include 

        
7条回答
  •  萌比男神i
    2020-12-10 20:43

    The easiest way would be to create a union, one part which contains each member individually and one part which contains an array. I'm not sure if platform-dependent padding might interfere with the alignment.

提交回复
热议问题