of topic: C programming style

Magnus Danielson cfmd at swipnet.se
Mon Nov 20 22:24:02 CET 2000


From: Martin Czech <czech at Micronas.Com>
Subject: of topic: C programming style
Date: Mon, 20 Nov 2000 20:44:46 +0100 (MET)

> What is the usuall C programming style with regard to 
> headers and includes?
> 
> I guess .h contains no actuall code?
> 
> 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?

Yes, this is the _USUAL_ way of doing things. Occasionally there is a
good reason to deviate from this path. Anyway, I do recommend that you
follow that principle.

> What is the proper path for  such inlcudes?

Usually just next to the rest of your code. Only if you make libraries
you have a reason to place things differntly. If you make large
projects you may run into other such cases. You will see when it
starts to hurt and you feel it is better to move headers to a common
directory. However, this occurs as you divide your source code into
several directories, so you usually know when the time has come. There
are LARGE projects which does not separate .h and .c files.

> Why do I need only to include math.h
> for all mathematicall functions, I mean there is no function
> code in it. 

Since it is all hidden in you libc.a/libc.so files which your C
compiler links your program against without asking you. That is why it
is called Standard C library. You do need the prototypes in math.h in
order to use what is in there.

> How does the compiler know where to get the code for some
> something.h header file? 

Either this is covered by the standard C library (which it
automatically takes in at linking time) or you will have to point at
the .o file or suitable .a file to link against. It does not know
anything by automagic, but if you toss the right files to it then it
will figure out where those procedures are, if they are.

Cheers,
Magnus




More information about the Synth-diy mailing list