Best articles about organizing code files in C?

A good book that covers a lot of this (for both C and C++) is Large Scale C++ Software Design, by John Lakos.

A good book that covers a lot of this (for both C and C++) is Large Scale C++ Software Design, by John Lakos: Also, a good rule of thumb to remember is "Never do anything that allocates memory in a header file.

Never do anything that allocates memory in a header file"---I like that. Succinct and a pearl of wisdom. – dmckee Jan 28 '09 at 19:57 just to make sure that I get that right, allocating memory in a header file is a problem because if two .

C files include it, there will be linker ambiguities. Am I correct? – Lazer May 20 '10 at 11:10 Just wondering, could you elaborate on that rule of thumb?

I can understand if its static allocation (e.g. A variable without an extern in front of it), but I don't really see how it's a problem, say, with malloc. – Edmund May 20 '10 at 11:36 @Lazer - yep @Edmund - Another way of looking at what I'm saying is declare things in . H files, don't define them.

If you have a variable that's being initialized and malloc'ed in a header file, you're asking for potential trouble. – George Sealy May 23 '10 at 4:46.

Specific to unix (and not to c, natch), but none the less: Recursive Make Considered Harmful With the build structure described, you can afford to use a lot of files. So each logical unit gets a header and a source file.

Read: Organizing Code Files in C and C++. It is very well written.

I think the best educational reading you're going to get on this subject, is reading something like the Linux Kernel source. It's got a good source layout, and is basically the standard large C project. Here is a guide for how source files should be put together for BSD source, as well.

Seriously, just start reading Kernel source and get a feel for how everything is put together. It's a very well planned project, obviously.

Regarding the files layout there are not too many alternatives. The partitioning is typically one of the following (package here is a single library or binary): .../project/.../package/module. {c,h} .../project/.../{src,include}/package/module.

{c,h} // non-interface headers go to src .../project/.../package/{src,include}/module. {c,h} // non-interface headers go to src The partitioning (1) is convenient in that all files belonging to particular package are stored in a single directory, so package can be easily moved around, but with this approach detaching API headers from private ones and detecting API changes is not trivial. (2) and (3) are very similar, they make API release and API changes detection trivial, while (2) is slightly easier for the case when you always release the whole project and (3) is slightly better when you release individial packages (e.g. For patching purposes) In any C/C++ project there is typically the following common packages: Common macros, and data types Logging package Application bootstrap package (in case there are more than 1 binaries in the project).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions