Skip to content

Instantly share code, notes, and snippets.

@hpcx82
Created May 31, 2012 08:24
Show Gist options
  • Save hpcx82/2841888 to your computer and use it in GitHub Desktop.
Save hpcx82/2841888 to your computer and use it in GitHub Desktop.
extern of array
extern char array[] = {1, 2, 3, 4};
// This is the right way of reference an extern array
extern char array[];
int main()
{
array[0] = 0;
array[1] = 1;
}
// compile pass, but in runtime, it would be a seg fault because:
// char* and char[] are of different types, actually, it will interpreted as
// array is a pointer with its address equals the real array's content.
// so here char* points to 04030201.
//
extern char* array;
int main()
{
array[0] = 0;
array[1] = 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment