Nuances in C: Struct Assignment in C

When I started this post, it was going to be a revolutionary post, talking about something that was really bothering me. As I have spent more time thinking about this, the answer seems so simple and obvious, still there was a time where I did not get this concept, so I here is a brief post on the topic, The question is, in straight C, will this work: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 #include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct point_t { int x,y; } Point; int main(int argc, char **argv) { Point a,b; int c[4] = {1, 2, 3, 4}; b = c; printf("b(%p) is now b[x] = %d, b[y] = %dn", &b, b.x, b.y); return 0; } In C++ this works no problem. Structs are teated like classes where all members have public scope. Assigning one struct to another simple implements the copy constructor that is created by the C++ language, but what about straight C? ...

March 13, 2008 · zacharyzacharyccom