473,508 Members | 2,327 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to distribute a C program into many C files ?

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 ra**********@gmail.com
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

Nov 14 '05 #1
4 1725

"Darius" <ra**********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
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
Nov 14 '05 #2

Allan Bruce wrote:
"Darius" <ra**********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
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.

Nov 14 '05 #3

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 <11**********************@g14g2000cwa.googlegroups .com>,
Darius <ra**********@gmail.com> 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 ra**********@gmail.com
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 /\/\/\/\/\
/\/\/ ch***@phaedsys.org www.phaedsys.org \/\/
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Nov 14 '05 #4
On 13 Apr 2005 06:46:39 -0700, in comp.lang.c , "Darius"
<ra**********@gmail.com> 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>
Nov 14 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
6076
by: Tom Lee | last post by:
Hi, I'm new to .NET 2003 compiler. When I tried to compile my program using DEBUG mode, I got the following errors in the C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7 \include\xdebug...
3
2554
by: Javi | last post by:
I have some doubts about what is the best method to distribute classes in .cpp and .h files: - Should I use a file per class? or should I group similar classes in one file? - Is it good to put a...
4
3946
by: Ed Landau | last post by:
Hi: I've just developped a really simple MS Access App. The VBA runs within the database. It uses some DLLs which I register with a script. It's on MS Access2003 (Office11). I've got 2003Pro...
0
2617
by: Danny J. Lesandrini | last post by:
Didn't get any takers on this post this morning at dotnet.General, so I'm reposting here. First, this is _not_ a question about how to get Crystal Reports to run on a client machine. I've got...
12
1787
by: Tolga | last post by:
Let's suppose that I have written a Python program and, of course, want to show it to the world ;-) So, do I have to distrubute my source code? Or is there a way to hide my code?
4
1249
by: mike7411 | last post by:
Is there an easy way to tell which files I need to distribute with my Microsoft Visual Studio 2005 MFC application? I keep getting a vague message on my target computer saying the application...
1
4056
by: akbar | last post by:
Hi, I am creating not-so-important opensource application written in python for Linux. I have two files python source in src directory, named blabla1.py and blabla2.py. There are byte compiled...
6
2507
by: Salman | last post by:
I would like to know how I can distribute the application that I create with Visual C++ express edition. I checked the menu options to find a deploy option similar to the one found on the Visual...
3
1060
by: qtrekkie | last post by:
Hi, Okay, I have been at this for about a month. I want to include .Net 3.5 framework with my programs in Visual Basic 2008 Express Edition. After very long and dreadful research I have concluded...
0
7224
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7120
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7380
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7494
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5050
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4706
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1553
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
415
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.