Iterating over same type struct members in C -


Is it possible to repeat a straight path, where all members are of the same type, using the pointer here There is some sample code that does not compile:

  #include & lt; Stdio.h & gt; # Include & lt; Stdlib.h & gt; Typify Configuration {int mem1; Int mem2; Intram 3; Int mem4; } Foo; Zero my_func (foo * data) {int i; Int * tmp = data; // This is the problem for the line (i = 0; i <4; ++ i) {++ tmp; Printf ("% d \ n", * tmp); }} Int main () {foo my_foo; // my_foo.mem1 = 0; My_foo.mem2 = 1; My_foo.mem3 = 2; My_foo.mem4 = 3; // my_func (and my_foo); Return 0; }  

Fu member must have an alliance in memory, to be one after another, thinking that your compiler / kernel buffer does not try to provide pile protection for overflow.

So my question is:

How would I be repeated on the same type of members of a C structure?

The simplest way would be to create a union, a part in which each member had different and one part In which there is an array. I'm not sure that platform dependent padding can interfere with alignment.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -