When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
12 messages ยท Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
Do not define functions in the header guards, unless it's inline functions
And use header guards to prevent repeated includes
If you have a main.h it already suggests something might be not quite right
If providing an inline definition, also be aware you must define it in a .c file too
static functions are also ok in headers
#include them, but compile each.#included into other source/header files. You will need include guards to prevent redefinition errors.Each source file becomes a translation unit during translation (expanding macros, remapping unicode characters, etc.)
Sometimes .ipp or .tpp for C++ are used for internal headers with function definitions.
it has a pretty easy fix,
animal.h:
#ifndef ANIMAL_H
#define ANIMAL_H
void some_fn(){
}
#endif
lion.h:
#include "animal.h"
#ifndef LION_H
#define LION_H
void some_lion_fn(){
some_fn();
}
#endif
main.c:
#include "animal.h"
#include "lion.h"
int main(){
return 0;
}
#ifndef LION_H
#define LION_H
// code
#endif
you should always do this in a header file, this will not redefine fucntions if files are included multiple times
ifndef expands to if not defined