Hey guys I am trying to put a bunch of functions into another .c file and and I also have a header file for that. I was wondering how I could take a .c file with a main method to #include that header file for those functions?
ihcuo
August 24, 2016, 4:26am
2
assuming files main.c, otherStuff.c, otherStuff.h are in the same folder you can use this command to compile: gcc *.c
main.c
#include "otherStuff.h"
int main(int argc, char** argv) { myFunction(); return 0; }
otherStuff.c
//function implementation int myFunction() { return 1+1; }
otherStuff.h
//function declaration int myFunction();
You may also need include guards:
In the C and C++ programming languages, an #include guard, sometimes called a macro guard, is a particular construct used to avoid the problem of double inclusion when dealing with the include directive. The addition of #include guards to a header file is one way to make that file idempotent. The following C code demonstrates a real problem that can arise if #include guards are missing:
In the C and C++ programming languages, #pragma once is a non-standard but widely supported preprocessor directive designed to cause the current source file to be included only once in a single compilation. Thus, #pragma once serves the same purpose as #include guards, but with several advantages, including: less code, avoidance of name clashes, and sometimes improvement in compilation speed. The most common alternative to #pragma once is to use #define to set an include guard macro, the name o...