News for hackers. Stuff that matters.
Re:Teaching C by Unklejoe on Tuesday May 10, 2016 @09:44PM (#11672079)
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;

Re:Teaching C by caf on Wednesday May 11, 2016 @02:25AM (#11673003)
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.

Re:Teaching C by mpweiher on Wednesday May 11, 2016 @04:48AM (#11673608)
> 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.

Re:Teaching C by gerbilly on Wednesday May 11, 2016 @08:47AM (#11674732)
> 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.

Re:Teaching C by eddyb on Wednesday May 11, 2016 @02:29AM (#11673016)
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