Re: Organisation of C programs

From: Thomas Matthews (Thomas_MatthewsSpitsOnSpamBots_at_sbcglobal.net)
Date: 07/28/04


Date: Wed, 28 Jul 2004 14:10:21 GMT

Richard Evans wrote:

> Hello,
>
> I am unsure of whether is Question is apt for this group, but
> that has never stopped anybody else.
>
> I believe I have a good understanding of the C language since my
> last post many years ago about passing pointers in functions.
>
> So now I am looking for resources describing how to layout and
> organize the parts of a program into subdirectories, how to
> include exported library headers, local headers and the overall
> collection of common includes, include guards, and preprocessor
> statements.
>
> I thought I would give people something different to talk about.
>
> Thanks in advance.
>
> Richard
>

This becomes a religious issue: everybody has their own
belief as to what is correct.

A common layout is:
Project
    |
    +-------
    | |
docs source
            |
            ----- include
Where the source contains all the ".c" files and the
include contains all the ".h" or header files.

I favor grouping by theme:

                   |
+-------------+---+----+--------+------------->
| | | |
utilities Flash UART Containers

In my opinion, this allows for better reuse of code.
Just point the search path to the correct directories.
I believe that processor specific code should be in
sub-directories under the themes (such as utilities
using processor specific features or assembly language).

I've only had one shop agree to to this. Most prefer to
dump all the files into one directory per project. That
way all the files can be easily duplicated for another
project (that is their definition of code reuse).

-- 
Thomas Matthews
C++ newsgroup welcome message:
          http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq:   http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
          http://www.comeaucomputing.com/learn/faq/
Other sites:
     http://www.josuttis.com  -- C++ STL Library book


Relevant Pages

  • Re: Slrn: display read headers by default on entering group
    ... FAQ or man page. ... Of which I follow the final suggestion which is using Esc p to pick up ... headers set as default. ... this myself but I assume that -1500 will automatically download this ...
    (news.software.readers)
  • RE: [SLE] [suse-xfree86] Blank screen w/GEForce FX 5200 AGP
    ... - the first one is a MSI GeForce4 MX440, if I want to get TV-out I've to ... > There should be a FAQ about this. ... Check the headers for your unsubscription address For additional commands send e-mail to suse-linux-e-help@suse.com Also check the archives at http://lists.suse.com Please read the FAQs: suse-linux-e-faq@suse.com ...
    (SuSE)
  • Re: Behringer pedals
    ... From the FAQ: ... other ngs? ... but then it's a real pain to 'view all headers' in every article ... Steve, you can do what you like. ...
    (uk.music.guitar)
  • Re: Dictionary Style Headers (Hard question)
    ... Intermediate User's Guide to Microsoft Word (supplemented version of ... Microsoft's Legal Users' Guide) http://addbalance.com/usersguide ... See also the MVP FAQ: http://www.mvps.org/word which is awesome! ... >> I'm pretty sure there's a Help topic on dictionary-style headers. ...
    (microsoft.public.word.pagelayout)

Loading