Skip to content

Instantly share code, notes, and snippets.

@GZShi
Created March 31, 2014 10:04
Show Gist options
  • Save GZShi/9889157 to your computer and use it in GitHub Desktop.
Save GZShi/9889157 to your computer and use it in GitHub Desktop.
#include <stdio.h>
struct str
{
int len;
char s[0];
};
struct foo
{
struct str *a;
};
int main(void) {
struct foo f = {0};
printf("int:%d\n", sizeof(int));
printf("char:%d\n", sizeof(char));
printf("str:%d\n", sizeof(struct str));
printf("foo:%d\n", sizeof(struct foo));
if(f.a->s) {
puts("====");
printf("f.a:%d\n", (int)(f.a));
printf("f.a->s:%d\n", (int)(f.a->s));
printf("f.a->len:%d\n", (int)(&(f.a->len)));
printf(f.a->s); // crash
}
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment