Created
August 25, 2010 13:12
-
-
Save mmisono/549468 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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