Last active
August 24, 2016 23:31
-
-
Save alexanderankin/8b2a053b7f52ccf7a660141ac90436db to your computer and use it in GitHub Desktop.
Learning C: extern keyword
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include "other_file.h" | |
int x; | |
int main(int, char **); | |
int main(int argc, char **argv) { | |
x = 5; | |
calculate(); | |
printf("%d\n", x); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "other_file.h" | |
extern int x; | |
void calculate() { | |
x = 6; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef other_file_header | |
#define other_file_header | |
void calculate(void); | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gcc main_file.c -o main_file.o -c && \ | |
gcc other_file.c -o other_file.o -c && \ | |
gcc -o output main_file.o other_file.o &&\ | |
./output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment