I guess pointer arithmetic isn't okay within structures. I guess order isn't guaranteed other. I'm recalling a lot of shaky code from my memory...
-
-
Replying to @misterpikul
All objects in C, including structures, have a /representation/, which is an overaid (permitted to alias) array of unsigned char [sizeof object]. Within this array relational operators and arithmetic are well-defined; otherwise offsetof would make no sense. Order is guaranteed.
1 reply 0 retweets 1 like -
Replying to @RichFelker
Order is guaranteed in structures? Even on bit arrays?
1 reply 0 retweets 0 likes -
Replying to @misterpikul
Bitfield members don't have addresses or offsets, so it's not really meaningful to ask about their order. Of course bytes corresponding to them appear in the representation though. Within a unit the order is implementation-defined.
1 reply 0 retweets 0 likes -
-
Replying to @misterpikul
Yes. In practice implementations (ABIs) define bitfield bit order to match byte order.
1 reply 0 retweets 2 likes -
Replying to @RichFelker @misterpikul
But back to your question, for something like struct { int a, b; } c;, the < operator and other relational operators are not defined for operands &c.a and &c.b (&c.a<&c.b is UB). However (char*)&c.a < (char*)&c.b is defined in the representation array.
1 reply 0 retweets 0 likes -
Replying to @RichFelker
If the char* array representation is the only one doesn't one imply the other? I'm assuming there is only one "physical" block of memory defined as the structure.
1 reply 0 retweets 0 likes -
Replying to @misterpikul
It's just a matter of how the < operator is defined. It's only defined for elements of the same array. There is an overlaid representation array of unsigned char [2*sizeof(int)]. There is not an overlaid array int[2].
2 replies 0 retweets 1 like -
Replying to @RichFelker
huh, i have tons more questions but they'll never end so i might as well find a book.
1 reply 0 retweets 1 like
Hah, good luck finding a book on C that's not all misinformation. ;-)
-
-
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.