473,549 Members | 2,455 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**********@gm ail.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 1728

"Darius" <ra**********@g mail.com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.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**********@g mail.com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.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************ **********@g14g 2000cwa.googleg roups.com>,
Darius <ra**********@g mail.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**********@gm ail.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
contradictio ns , 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**********@g mail.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
6093
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 file as folows. I need help to resolve them ASAP: cl /c /nologo /MDd /W3 /Od /GR /GM /Zi /GX /D "_DEBUG" /D " WIN32" /D "_W INDOWS" /D "_WINDLL"...
3
2557
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 lot of class declarations in the same .h, and their definitions in different .cpps? - And, to the contrary, many definitions in one cpp and...
4
3950
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 but could get Ent. Never having done this before, I'm not sure what I need to do in order to be able to distribute it. I'd like not to require...
0
2621
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 all the merge modules added to the project and it's working fine. The question is about distributing my .RPT files. 1) Initial Setup Project...
12
1797
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
1252
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 configuration is incorrect.
1
4058
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 files too, named blabla1.pyc and blabla2.pyc. Should I distribute these files (pyc files) to users? If I don't distribute them, and user installed my...
6
2511
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 Basic Express Edition but could not find one. I have even searched the help files and could not find anything useful for me. I want to simply...
3
1064
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 that I am missing following folder: DotNetFX35. Now, it would be extremly helpful if someone could put it in a compressed folder and attach it to...
0
7542
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7467
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7982
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6066
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5385
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3514
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3494
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1961
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 we have to send another system
0
783
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.