Archived

This topic is now archived and is closed to further replies.

Agape

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

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
// file.cpp

// global variable
int x;

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

// otherFile.cpp

extern int x; // allow access to global variable x from file.cpp

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites