Skip to content

Instantly share code, notes, and snippets.

@rmarianski
Created December 29, 2014 15:41
Show Gist options
  • Save rmarianski/89b11618bd0aa8220073 to your computer and use it in GitHub Desktop.
Save rmarianski/89b11618bd0aa8220073 to your computer and use it in GitHub Desktop.
Embed structures in c
#include <stdio.h>
typedef struct point {
int x, y;
} point;
typedef struct point3d {
struct point;
int z;
} point3d;
int main() {
point p1 = {.x=1, .y=2};
point3d p2 = {.x=1, .y=2, .z=3};
printf("%d,%d\n", p1.x, p1.y);
printf("%d,%d,%d\n", p2.x, p2.y, p2.z);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment