Difference between revisions of "C header structure"
From ATI public wiki
(Created page with "==sample.h== <source lang="c" collapse="false" first-line="2"> →include guard - ei lase funktsioone üle defineerida: #ifndef SAMPLE_H #define SAMPLE_H /* Funktsiooni dek...") |
|||
Line 32: | Line 32: | ||
} | } | ||
</source> | </source> | ||
+ | |||
+ | Building | ||
+ | |||
+ | '''gcc mainc. sample.c -o sample''' |
Revision as of 08:06, 16 December 2014
sample.h
/* include guard - ei lase funktsioone üle defineerida*/
#ifndef SAMPLE_H
#define SAMPLE_H
/* Funktsiooni deklaratsioon */
int sample(int a);
#endif
sample.c
#include "sample.h"
int sample(int a) {
/* Funktsiooni definitsioon */
return a * a;
}
main.c
#include <stdio.h>
#include "sample.h"
int main(void) {
int a = sample(4);
printf("%d\n", a);
return 0;
}
Building
gcc mainc. sample.c -o sample