Skip to content

Instantly share code, notes, and snippets.

@mmisono
Created August 25, 2010 13:12
Show Gist options
  • Select an option

  • Save mmisono/549468 to your computer and use it in GitHub Desktop.

Select an option

Save mmisono/549468 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char const* argv[])
{
struct _hoge {
int x;
int y;
int len;
#define HEADER_SIZE (long)&((struct _hoge *)NULL)->data
char data[1];
} *hoge;
int len = 3;
hoge = (struct _hoge *)malloc(len+1 + HEADER_SIZE);
hoge->x = 1;
hoge->y = 2;
hoge->len = len;
hoge->data[0] = 'a';
hoge->data[1] = 'b';
hoge->data[2] = 'c';
hoge->data[3] = '\0';
printf("%d %d %d %s\n",hoge->x,hoge->y,hoge->len,hoge->data);
return 0;
}
/*
* result:
* 1 2 3 abc
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment