How to distribute a C program into many C files ?

Discussion in 'C Programming' started by Darius, Apr 13, 2005.

  1. Darius

    Darius Guest

    How to distribute a C program into many C files ?

    this is the first question a C programmer asks after learning C basics,
    Questions like
    --what is a header file
    --where should i put global variables
    --where should i put declaration and definitions
    --where should i put macros
    --when to use static functions and variables

    Is there an existing C draft for this, i mean a draft that specifies
    some conventions , following which you can save yourself from double
    defination error, undefined variables errors etc ?

    I am planning to make such a draft rather "We" can develop such a
    draft. Right now i have written some trivial conventions and i'll post
    its link to the community in 1-2 days, as soon as i finalize it.
    My idea is that, everybody(who is interested) will read the draft and
    see if there is something missing or if something is wrong. And i will
    make the necessary changes and mail the new link (new version) in this
    thread. In this way the draft will adaptively improve. In this way we
    can develop a good convention to make a proper C project, which will be
    least vulnerable to bugs.

    Here are the rules to do this :-

    1) Mail the changed file or suggestions to me at
    with subject "C-project-draft"
    2) If you are making some changes then comment the places where you
    have changed it.
    3) I will see the changes and if i find some ambiguities or
    contradictions , i'll discuss it here.
    4) After making necessary changes, i'll release the newer version with
    your name appended to the file along with newer version.
    ranveer kunal<email>(0.1), eric sosman<email>(0.2),...
    5) You can suggest any rule.

    And if such a draft exsists, kindly give its link here.

    ----------------
    darius
     
    Darius, Apr 13, 2005
    #1
    1. Advertising

  2. Darius

    Allan Bruce Guest

    "Darius" <> wrote in message
    news:...
    > How to distribute a C program into many C files ?
    >
    > this is the first question a C programmer asks after learning C basics,
    > Questions like
    > --what is a header file
    > --where should i put global variables
    > --where should i put declaration and definitions
    > --where should i put macros
    > --when to use static functions and variables


    Basically you put the function prototypes in the header file, and include
    the files that are necessary only for the prototypes - you can add some
    definitions here if they are required externally to your functions. All
    function definitions in the c file. I put my struct definitions in the
    header file but this depends on your style.
    Basically the header should be as minimal as possible but you dont want to
    repeat any code anywhere. As for macros, generally in your source file is
    best. If you want macros available across many files, then make a separate
    ..c file for them with a single header, eg. myMacros.h (which would be
    empty).
    Global variables should be avoided as much as possible but if needed I put
    them in the c file which has my entry point (main). To access these from
    other modules, you must declare them like:
    extern int myGlobalInt;
    (they are declared normally in the main c file).

    Allan
     
    Allan Bruce, Apr 13, 2005
    #2
    1. Advertising

  3. Darius

    Darius Guest

    Allan Bruce wrote:
    > "Darius" <> wrote in message
    > news:...
    > > How to distribute a C program into many C files ?
    > >
    > > this is the first question a C programmer asks after learning C

    basics,
    > > Questions like
    > > --what is a header file
    > > --where should i put global variables
    > > --where should i put declaration and definitions
    > > --where should i put macros
    > > --when to use static functions and variables

    >
    > Basically you put the function prototypes in the header file, and

    include
    > the files that are necessary only for the prototypes - you can add

    some
    > definitions here if they are required externally to your functions.

    All
    > function definitions in the c file. I put my struct definitions in

    the
    > header file but this depends on your style.
    > Basically the header should be as minimal as possible but you dont

    want to
    > repeat any code anywhere. As for macros, generally in your source

    file is
    > best. If you want macros available across many files, then make a

    separate
    > .c file for them with a single header, eg. myMacros.h (which would be


    > empty).
    > Global variables should be avoided as much as possible but if needed

    I put
    > them in the c file which has my entry point (main). To access these

    from
    > other modules, you must declare them like:
    > extern int myGlobalInt;
    > (they are declared normally in the main c file).
    >
    > Allan


    read the mail carefully, i am not asking anything, i am proposing
    something.

    please read the previous mail carefully.
     
    Darius, Apr 13, 2005
    #3
  4. Darius

    Chris Hills Guest

    Search on "C coding standards" "coding standards" "C style guides"
    "MISRA-C"

    then there is NASA's coding standard onthe web and Jack Ganssle's web
    site and thousands of others




    In article <>,
    Darius <> writes
    >How to distribute a C program into many C files ?
    >
    >this is the first question a C programmer asks after learning C basics,
    >Questions like
    >--what is a header file
    >--where should i put global variables
    >--where should i put declaration and definitions
    >--where should i put macros
    >--when to use static functions and variables
    >
    >Is there an existing C draft for this, i mean a draft that specifies
    >some conventions , following which you can save yourself from double
    >defination error, undefined variables errors etc ?
    >
    >I am planning to make such a draft rather "We" can develop such a
    >draft. Right now i have written some trivial conventions and i'll post
    >its link to the community in 1-2 days, as soon as i finalize it.
    >My idea is that, everybody(who is interested) will read the draft and
    >see if there is something missing or if something is wrong. And i will
    >make the necessary changes and mail the new link (new version) in this
    >thread. In this way the draft will adaptively improve. In this way we
    >can develop a good convention to make a proper C project, which will be
    >least vulnerable to bugs.
    >
    >Here are the rules to do this :-
    >
    >1) Mail the changed file or suggestions to me at
    >with subject "C-project-draft"
    >2) If you are making some changes then comment the places where you
    >have changed it.
    >3) I will see the changes and if i find some ambiguities or
    >contradictions , i'll discuss it here.
    >4) After making necessary changes, i'll release the newer version with
    >your name appended to the file along with newer version.
    >ranveer kunal<email>(0.1), eric sosman<email>(0.2),...
    >5) You can suggest any rule.
    >
    >And if such a draft exsists, kindly give its link here.
    >
    >----------------
    >darius
    >


    /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
    \/\/\/\/\ Chris Hills Staffs England /\/\/\/\/\
    /\/\/ www.phaedsys.org \/\/
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
     
    Chris Hills, Apr 13, 2005
    #4
  5. On 13 Apr 2005 06:46:39 -0700, in comp.lang.c , "Darius"
    <> wrote:

    >How to distribute a C program into many C files ?
    >
    >this is the first question a C programmer asks after learning C basics,
    >Questions like
    >--what is a header file


    a file that is textually included in your C file by a #include
    directive.

    >--where should i put global variables


    Ideally you should not have any. If you do, declare and initialise
    them in one C file and have extern declarations in a header.

    >--where should i put declaration and definitions


    public declarations belong in headers, static ones in the relevant
    source file. Definitions can only go in source files.

    >--where should i put macros


    headers

    >--when to use static functions and variables


    whenever you need private functions or data. Steer clear of static
    data in threaded apps.

    >Is there an existing C draft for this, i mean a draft that specifies
    >some conventions ,


    The rules vary from company to company, and you need to find out what
    is house style where you currently work. Typically tho, its as above.


    --
    Mark McIntyre
    CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
    CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>
     
    Mark McIntyre, Apr 13, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shrinivas
    Replies:
    4
    Views:
    2,446
    Jerry III
    Aug 21, 2003
  2. =?Utf-8?B?Sm9obiBCYWlsZXk=?=

    Can you still indicate to distribute files locally in ASP.Net 2.0

    =?Utf-8?B?Sm9obiBCYWlsZXk=?=, Jun 16, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    363
    =?Utf-8?B?Sm9obiBCYWlsZXk=?=
    Jun 16, 2005
  3. dee
    Replies:
    2
    Views:
    399
  4. Kevin
    Replies:
    12
    Views:
    762
  5. January Weiner

    Best way to distribute program with modules

    January Weiner, Mar 3, 2008, in forum: Perl Misc
    Replies:
    1
    Views:
    100
    Ben Morrow
    Mar 3, 2008
Loading...

Share This Page