of topic: C programming style
Thomas Hudson
thudson at tomy.net
Mon Nov 20 22:10:42 CET 2000
Martin Czech wrote:
>
> I understand that something.h should contain some switches,
> defines and function prototypes with some comments
> of all functions in something.c, which contains all the sources.
>
> Is this so?
This is true, but it doesn't have to be.
> What is the proper path for such inlcudes?
The normal search on Unix/Linux is /usr/include and
/usr/local/include. You can add additional search paths
on the command line with the -I flag:
$ gcc -o myprogram -I. -I/some/other/includedir myprogram.c
> Why do I need only to include math.h
> for all mathematicall functions, I mean there is no function
> code in it.
To specify prototypes, and sometimes to pick up macros like
min and max. You'll still need to link against the math
library:
$ gcc -o myprogram mypreogram.c -lm
>
> How does the compiler know where to get the code for some
> something.h header file?
>
For the math library you need to specify it, but for many
includes (string.h, ctype.h, etc) the code for these is in
the main C library, which the compiler/linker automatically
links against. If you use the compiler to also link it will
add the standard c library automatically, if you call the
linker separately you would have to specify it:
$ gcc -c myprogram.c
$ ld -o myprogram -lc -lm
The normal search path for libraries is /lib, /usr/lib.
If a library is named libsomething.a, you specify -lsomething
on the command line.
Tomy
More information about the Synth-diy
mailing list