It'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.
> 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.
> 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.
I believe C++14 adds the first sane C-family array type:
template<typename T, size_t N> class array { T data[N]; };
Re:Teaching C
by Kristine1975 on Wednesday May 11, 2016 @03:00AM
(#11673140)
std::array is in C++11
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;