From Darin McBride · 1996-04-05 08:13 · #73616 in EMULATE
In reply to extern by Jeff Siegel
Hello Jeff!
05 Apr 96 01:15, Jeff Siegel wrote to All:
JS> Hi, I'm learing c++ and was wondering what the 'extern' command
JS> does. The Watcom c++ 10.5 help files don't really say anything
JS> about it. Also I am trying to compile a .c file I found on the
This is a base command of C. What it basically means are the following:
A) in all modules, the following item may not actually be in this C file, but will definately be there at link time
B) in C++, if the item is *also* defined later on, it means that this item will be available to other modules.
For example:
myhead.h:
extern int i; // this means that you can use a global variable 'i' as an int
// and that it will be available when you link.
void foo(); // the extern is implied for functions
file1.c:
#include "myhead.h"
int i; // we have to actually have it somewhere...
void foo()
{
i = 5;
}
file2.c:
#include "myhead.h"
void bar()
{
cout << i << endl;
}
int main()
{
foo();
bar();
return 0;
}
Running this would print '5'.
In file2.c, when you include "myhead.h", it brings the line 'extern int i' into the source, and the compiler recognizes that 'i' will be there later. In file1.c, the compiler also notices that you define 'i' (using 'int i') and so it creates room for the variablee 'i' in that module.
If all this confuses the HECK out of you, it's because I'm writing this at 2:20 AM... :-) In that case, ask your sysop (Gerry) to give you my BBS number (from the nodelist), and you can call my system. :-)
JS> net and the compiler can't reconize a command calle 'getvert'
JS> what does this do and how can I get it working with Watcom c++?
That one I don't recognize...
Darin McBride
--- GoldED/2 2.42.G0614
* Origin: Tanktalus' Tower BBS/RPGs Galore! (1:342/5015)