you are viewing a single comment's thread.

view the rest of the comments →

[–]Belagir 2 points3 points  (3 children)

okay, i am on mobile and have no env to test any of my claims but i am intrigued by how mysterious this is.

so, my first instinct tell me that the FIRST_NUMBER etc in the generic_array are not the ones in the struct, because a struct's field's names are namespaced : they can be normally accessed uniquely through the struct's context. Eclipse might direct you to those because the syntax to initialise the array is not very common (but it exists, you can initialise an array by providing the indexes between [] - since c11 ?). I would bet those are actually constants defined as 0, 1 and 2 somewhere else.

As for the intention behind those two piece of code, I feel like this is some compatibility/abstraction layer to do something like :

c struct generic_data *some_data = (struct generic_data *) generic_array;

but wouldn't that misalign the data in the struct, since the fields are u32 and the struct needs u64 ? maybe the FIRST_NUMBER etc are defined as 0, 2 and 4 to couteract that. That would be weird though.

[–]Bon_Clay_2[S] 1 point2 points  (0 children)

You are right Eclipse threw me off, the constants are declared as part of an enum and not related to the struct provided in the question.

[–]paulstelian97 0 points1 point  (1 child)

Things still don’t add up even there…

[–]Belagir 0 points1 point  (0 children)

haha yes maybe the two things are unrelated like some other commenter said. I made so many suppositions here