C Programming help .....wtf ?!?!
Kurt Wall
kwall
Sat Jan 29 17:20:18 PST 2005
On Saturday 29 January 2005 13:54, Ben Duncan wrote:
> And while we are on this subject ....
>
> Can anyone point / help me with C coding standards.
> Like what variables names should be, if used external or internal,
> static ..etc..etcc.
Variable names should be consistent and self-documenting. C doesn't have
a notion for "internal" variables, although all C objects are either
internal or external in terms of linkage. Anything dclared inside a
function (including the formal parameters) are internal; everyhting
else is external.
As others have noted, declaring functions and variable static keeps them
file local, meaning it turns objects that would have external linkage
(visiable to other files/modules) into objects with internal linkage.
C does have the extern keyword, which makes C's otherwise simple notions
of scope and linkage (and declaration and definition, for that matter)
arcane.
> Where typedef/structure definitions and allocations should be and go
> in a multi-file program system ....
typedefs and structure definitions are usually declared in header files.
Depending on the size of your project, you can usually keep headers in
the same directory as your sources. In other cases, it is easier from a
management point of view to create a top-level includes directory and
use -I to tell the compiler where to find them.
Allocation typically happens in the file that uses the allocated memory,
unless you are talking about some other type of allocation.
> I have gottena lot of things working with SLAG, but I want to clean
> up up the source before doing an initial release of it.
HTH.
Kurt
More information about the Linux-users
mailing list