4 ms·
To add to the oddities: You can copy entire structures by value by doing "x = y". This ends up being implemented as a memory copy loop, but I'm not sure what
by Unklejoe 10y ago
To add to the oddities:
You can copy entire structures by value by doing "x = y".
This ends up being implemented as a memory copy loop, but I'm not sure what happens with the padding bytes. There's a chance they get copied as well, but I really don't know.
In the code base I work with, it's common to see arrays inside of a structure which they're the only member of. This makes it a little easier to copy them, though I'm not sure if that was the intended purpose.
Something like this would be defined in a header...
typedef struct {
char myArray[50];
} Test_Struct_T;
- caf 10y agoIt's not specified what happens to the memory padding bytes on structure assignment. Hence: you can't use memcmp() to reliably compare structures for equality.
- eddyb 10y agoI believe C++14 adds the first sane C-family array type: template<typename T, size_t N> class array { T data[N]; };
- Kristine1975 10y agostd::array is in C++11
- mpweiher 10y ago> You can copy entire structures by value by doing "x = y". That wasn't in the original language, though it's a pretty old extension.
- gerbilly 10y ago> That wasn't in the original language, though it's a pretty old extension. That's why I don't recognize that feature. I guess we didn't have it back when I was doing a lot of C.