🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Beginner : extern expression

Started by
3 comments, last by GameDev.net 24 years, 8 months ago
File1.h:
------------

extern int xyz ();

File1.cpp:
--------------

int xyz ()
{
}

File2.cpp:
--------------

#include "file1.h"
int main ()
{
xyz();
}

I hope this helps.

Advertisement
Umm... correct me if I'm wrong, but you shouldn't need to use the extern keyword for functions. You only need to extern global variables from another file.


Six

You're right, you don't need to put the keyword 'extern' before the prototype if it's in a header file.
However you can also extern a function by typing
extern int xyz(void);
In file2.cpp instead of the header.

(just to confuse you)

[This message has been edited by MikeD (edited September 27, 1999).]

I have two .cpp file and want to use the function xyz from File1 in File2 .
I wrote extern functio xyz in the File2 header to let the compiler know that where is an function in another file.
but he said : function xyz already declared in File1.obj .
How can I you function from other files ???
I've no C-Reference book and dont know when to use extern or whatever .

Hope for answer and Thank you

I'm not confused at all; I just like to write solid, readable code. Using 'extern' when the language doesn't enforce it doesn't make bad code, it makes readable code. In this case, it makes it OBVIOUS that it's a declaration, so someone glancing at your code knows right away without looking anywhere else.

There, I'm done

This topic is closed to new replies.

Advertisement