Skip to content

Instantly share code, notes, and snippets.

@zhangyuchi
Created November 18, 2014 02:46
Show Gist options
  • Save zhangyuchi/c46fd35b69b50ce63b4b to your computer and use it in GitHub Desktop.
Save zhangyuchi/c46fd35b69b50ce63b4b to your computer and use it in GitHub Desktop.
pointer and array in struct
#include <stdio.h>
struct str{
int len;
char s[0];
};
struct foo {
struct str *a;
};
int main(int argc, char** argv) {
struct foo f={0};
if (f.a->s) { //won't crash
printf( f.a->s); //will crash
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment