I just found another code base at work, where developers sequentially use the address of the first structs element when copying / comparing / setting, and not in the structure itself. Here is a simple example.
First enter the structure type:
typedef struct { int a; int b; } foo_t;
Then there is a function that creates a copy of such a structure:
void bar(foo_t *inp) { foo_t l; ... memcpy(&l.a, &inp->a, sizeof(foo_t)); ... }
I myself would not write the memcpy call in this way, and I began with the suspicion that the original developers simply did not quite understand the pointers and structures in C. However, now I saw this in two unrelated code bases, without common developers, so I start to doubt myself .
Why use this style?
c struct
Magnus Nov 04 '13 at 20:41
source share