Created
May 31, 2012 08:24
-
-
Save hpcx82/2841888 to your computer and use it in GitHub Desktop.
extern of array
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
extern char array[] = {1, 2, 3, 4}; |
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
// This is the right way of reference an extern array | |
extern char array[]; | |
int main() | |
{ | |
array[0] = 0; | |
array[1] = 1; | |
} |
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
// 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