1
I saw on the site with link below that in ANSI C pattern there is the extern keyword, but never seen being used in practice. What exactly does it?
1
I saw on the site with link below that in ANSI C pattern there is the extern keyword, but never seen being used in practice. What exactly does it?
3
Dude, after researches I understood that extern serves to indicate that a variable has already been defined in another part of the program as a whole. For example, if you divide a giant code into 2 parts. You should indicate to the compiler that you are using these variables in a block (file 2) but they have been initialized in another block (code 1).
for example:
Code 1:
int count;
float sum;
int main(void)
{
...
return 0;
}
Code 2:
extern int count;
extern float sum;
int RetornaCount(void)
{
return count;
}
Here’s a link that explains much better than me: http://mtm.ufsc.br/~Azeredo/cursoC/aulas/ca20.html
I hope I’ve helped.
Browser other questions tagged c
You are not signed in. Login or sign up in order to post.
Correct. And one of the utilities of the files . h is precisely to contain the statements of variables with extern, to avoid errors of copying and pasting.
– marcus