Methods used extern

Author:Anonymous    Updated:2008-10-17 12:08:53

# include "stdafx.h"

   1.extern variables used in the statement, there is often such a role, you *. c file a statement of a global variables, the overall situation of the variables used to be, on the *. h and in a statement to extern .

   2. If the function of the statement with the keyword extern, is the only hint that this function may be the source of other documents definition, there is no other role. That the statement did not distinguish between the two functions:

   extern int f (); and int f ();

   =================================

   If the definition of the functions c / cpp file in the corresponding headers in a statement the definition of the function, then the other in the c / cpp file to the use of these functions, only the first document to contain.

   If you do not want to include the first document, then c / cpp statement in the function. In general, the definition of a statement in this document do not have to function "extern", a statement in the definition of other documents used in the function "extern", so in this document other documents call on the definition of the functions do not include the first paper

   include "*. h" function to the statement, a statement can be used directly.

   =================================

   For example:

   / / extern.cpp as follows:

  

   / / extern.cpp: Defines the entry point for the console application.

   / /

  

   # include "stdafx.h"

   extern print (char * p);

   int main (int argc, char * argv [])

   (

   char * p = "hello world!";

   print (p);

   return 0;

  )

   / / print.cpp as follows

   # include "stdafx.h"

   # include "stdio.h"

   print (char * s)

   (

   printf ( "The string is% s \ n", s);

  )

  

   The results can be normal operation of the output. If the "extern" removed, the process can still operate normally.

  

   can be seen, "extern" in the statement that non-essential functions, only used to mark the function definition in this document, or other document definition. As long as you use the function in a statement before, then you can not contain a header.

Previous:HOOK used to disable the keyboard and mouse click
Next:Data deleted from the document
User Reviews
Site Search
Recommended article
AD