Iterating over same type struct members in C

后端 未结 7 578
醉酒成梦
醉酒成梦 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条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-10 20:36

    From the language point of view: you can't. data members of the struct are not... er.. "iteratible" in C, regardless of whether they are of the same type or of different types.

    Use an array instead of a bunch of independent members.

提交回复
热议问题