Making source code files comunicate
Posted: Sat Jan 21, 2006 12:25 pm
Hi, I`m a newbe, and thought, how do I make source code files communicate. (Newbie to the languages I know ;D) ;
The Place to Start for Operating System Developers
http://forum.osdev.org./
Code: Select all
//SOURCE FILE 1
char my_communicator1;
void my_function1(){
printf("Hi! this is source file #1\n");
printf("my_communicator1=%i\n",my_communicator); //print what the value is
}
//SOURCE FILE 2
extern my_communicator1 //this says that the variable is in a different object file(source file)
extern void my_function1(); //same as above but this is a function
void main(){ //this is the main
my_communicator=4;
my_function1();
my_communicator=243;
my_function1();
}
//END
Code: Select all
// source1.c
void myFunc(int x)
{
do_something();
}
Code: Select all
// source2.c
int main()
{
myFunc(20);
return 0;
}
Code: Select all
//mystuff.h
void myFunc(int);
Code: Select all
//source1.c
#include "mystuff.h"
void myFunc(int x)
/* compiler will be able to check you're conforming to
definition in mystuff.h and warns you otherwise
*/
{
do_something();
}
Code: Select all
// source2.c
int main()
{
/* compiler detects you're passing a wrong type of
* argument and complains.
*/
myFunc("Hello World");
return 0;
}