extern -- what does it mean and why is it used?

Started by
2 comments, last by Agape 20 years, 9 months ago
In Nehe''s lesson 31, there is a header file that contains: extern GLuint LoadGLTexture( const char *filename ); // Load Bitmaps And Convert To Textures What does "extern" mean? Why create a seperate header file (there are other header files in this lesson) for just this one line?
Advertisement
extern means, in your code, that your function is declared here, but defined in another file (i believe).

the Seby
------------------------ - Seby -www.dfhi-bomber.fr.st
// file.cpp

// global variable
int x;

// ----------------------------------------------

// otherFile.cpp

extern int x; // allow access to global variable x from file.cpp
quote:Original post by Agape
In Nehe''s lesson 31, there is a header file that contains:

extern GLuint LoadGLTexture( const char *filename ); // Load Bitmaps And Convert To Textures


What does "extern" mean? Why create a seperate header file (there are other header files in this lesson) for just this one line?


I think that a function prototype is extern by default, so the extern is unneeded in this case. You only really need it for variables (which are not extern by default).

This topic is closed to new replies.

Advertisement