473,387 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

multi-file programs - main.c recommended?

Can anways explain why many multi-file programs I've seen don't have a
main.c file, instead main() is hidden in a file with a different name?
Is this just a preference, or is there an unspoken rule (or advantage).

I've been calling the file with main, main.c, and I was wondering if
there are any caveats against this (that might prevent me from being
laughed at or something).

Nov 14 '05 #1
11 1614
G Patel wrote:
Can anways explain why many multi-file programs I've seen don't have a
^^^
anyone
main.c file, instead main() is hidden in a file with a different name? Is this just a preference, or is there an unspoken rule (or advantage).
I've been calling the file with main, main.c, and I was wondering if
there are any caveats against this (that might prevent me from being
laughed at or something).


Nov 14 '05 #2
G Patel <ga********@gmail.com> wrote:
Can anways explain why many multi-file programs I've seen don't have a
main.c file, instead main() is hidden in a file with a different name?
Is this just a preference, or is there an unspoken rule (or advantage). I've been calling the file with main, main.c, and I was wondering if
there are any caveats against this (that might prevent me from being
laughed at or something).


There' nothing that would force you to call the file with the main()
function main.c - but there's also nothing that would keep you from
doing that. Personally, I prefer to give the file with main() a name
that reflects the one of the final program since I feel that this is
somehow the most logial choice (probably due to having started with
FORTRAN where the equivalent of main() was a function with the name
of the final program (IIRC) and it thus was natural to name the file
accordingly), but if you feel differently do it as you like and no-
one is going to laugh;-) With tools like grep it is simple to find
out where main() is, so there's no reason to worry.

Regards, Jens
--
\ Jens Thoms Toerring ___ Je***********@physik.fu-berlin.de
\__________________________ http://www.toerring.de
Nov 14 '05 #3
In article <11*********************@g14g2000cwa.googlegroups. com>,
G Patel <ga********@gmail.com> wrote:
Can anways explain why many multi-file programs I've seen don't have a
main.c file, instead main() is hidden in a file with a different name?
Is this just a preference, or is there an unspoken rule (or advantage).

I've been calling the file with main, main.c, and I was wondering if
there are any caveats against this (that might prevent me from being
laughed at or something).


There is no rule for/against this; you may call that file main.c
if you like.

If I were writing a program to play the game of solitaire,
chances are that the file that contained main() would be
called solitaire.c.

Strangely enough, if I were writing a program to play chess,
chances are that the file that contained main() would be
called main.c. There is no particular logic behind this.
It's a matter of whim/style.

--
Rouben Rostamian
Nov 14 '05 #4
"G Patel" <ga********@gmail.com> writes:
Can anways explain why many multi-file programs I've seen don't have a
main.c file, instead main() is hidden in a file with a different name?
Is this just a preference, or is there an unspoken rule (or advantage).

I've been calling the file with main, main.c, and I was wondering if
there are any caveats against this (that might prevent me from being
laughed at or something).


If you have a software package that generates multiple executables,
you might have multiple files containing a main() function. In such a
case, it probably makes sense for each such source file to have a name
reflecting the name of the executable. (Or you can put them in
separate directories and call each one "main.c".)

There's no universal convention, and the C language doesn't care.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #5
there are many which have main.c , try google for MLAPM (used in n-body
simulations)

G Patel wrote:
Can anways explain why many multi-file programs I've seen don't have a main.c file, instead main() is hidden in a file with a different name? Is this just a preference, or is there an unspoken rule (or advantage).
I've been calling the file with main, main.c, and I was wondering if
there are any caveats against this (that might prevent me from being
laughed at or something).


Nov 14 '05 #6
"G Patel" <ga********@gmail.com> wrote in message news:<11*********************@g14g2000cwa.googlegr oups.com>...
Can anways explain why many multi-file programs I've seen don't have a
main.c file, instead main() is hidden in a file with a different name?
Is this just a preference, or is there an unspoken rule (or advantage).

I've been calling the file with main, main.c, and I was wondering if
there are any caveats against this (that might prevent me from being
laughed at or something).


I always use
$ grep -n main\( *.c
to find main if there is no main.c or [PROGRAMNAME].c
Nov 14 '05 #7
On 2 Mar 2005 17:14:49 -0800, "G Patel" <ga********@gmail.com> wrote:
Can anways explain why many multi-file programs I've seen don't have a
main.c file, instead main() is hidden in a file with a different name?
Is this just a preference, or is there an unspoken rule (or advantage).

I've been calling the file with main, main.c, and I was wondering if
there are any caveats against this (that might prevent me from being
laughed at or something).


Normally, you would put the main() in a file which has a name
appropriate for your program. For example, if your program is going to
be called widget, put the main in widget.c.

Consider - if I always put main() in a file named main.c, after 20
years of C programming, I would now have a thousand files named
main.c! How would I remember which was which?

--
Al Balmer
Balmer Consulting
re************************@att.net
Nov 14 '05 #8
Alan Balmer wrote:
Normally, you would put the main() in a file which has a name
appropriate for your program. For example, if your program is going to be called widget, put the main in widget.c.

Consider - if I always put main() in a file named main.c, after 20
years of C programming, I would now have a thousand files named
main.c! How would I remember which was which?


You shouldn't have to 'remember.'
.../[Program 1 name]/main.c
.../[Program 2 name]/main.c
.../[Program 3 name]/main.c
.../[Program 4 name]/main.c
Nov 14 '05 #9
Alan Balmer <al******@att.net> writes:
[...]
Normally, you would put the main() in a file which has a name
appropriate for your program. For example, if your program is going to
be called widget, put the main in widget.c.

Consider - if I always put main() in a file named main.c, after 20
years of C programming, I would now have a thousand files named
main.c! How would I remember which was which?


Presumably you wouldn't have to remember; you could tell by the name
of the directory it's in. (This assumes a programming environment
that keeps source files in directories, of course.)

I'm not saying you *should* call it main.c, only suggesting that doing
so doesn't necessarily mean you should be laughed at.

I consider either "widget.c" or "main.c" to be a reasonable name for
the source file containing the main program for "widget". The name
"main.c" could cause problems if a single project has multiple main
programs, but you can always put them in separate subdirectories.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #10
On Thu, 03 Mar 2005 20:18:28 GMT, Keith Thompson <ks***@mib.org>
wrote:
Alan Balmer <al******@att.net> writes:
[...]
Normally, you would put the main() in a file which has a name
appropriate for your program. For example, if your program is going to
be called widget, put the main in widget.c.

Consider - if I always put main() in a file named main.c, after 20
years of C programming, I would now have a thousand files named
main.c! How would I remember which was which?
Presumably you wouldn't have to remember; you could tell by the name
of the directory it's in. (This assumes a programming environment
that keeps source files in directories, of course.)


If your programming career is sufficiently short, simple, and
concentrated in one environment, that will work. More or less.
I'm not saying you *should* call it main.c, only suggesting that doing
so doesn't necessarily mean you should be laughed at.
I'll make up my own mind on that <g>.
I consider either "widget.c" or "main.c" to be a reasonable name for
the source file containing the main program for "widget". The name
"main.c" could cause problems if a single project has multiple main
programs, but you can always put them in separate subdirectories.


Hmm... That would mean the project I'm on now would have 432
directories. They could, of course, be organized as subdirectories
under the current set of directories, and I'm sure we could eventually
figure out how to get the makefiles to work again ...

Maybe next year.

--
Al Balmer
Balmer Consulting
re************************@att.net
Nov 14 '05 #11
Alan Balmer wrote:
On 2 Mar 2005 17:14:49 -0800, "G Patel" <ga********@gmail.com> wrote:

Can anways explain why many multi-file programs I've seen don't have a
main.c file, instead main() is hidden in a file with a different name?
Is this just a preference, or is there an unspoken rule (or advantage).

I've been calling the file with main, main.c, and I was wondering if
there are any caveats against this (that might prevent me from being
laughed at or something).

Normally, you would put the main() in a file which has a name
appropriate for your program. For example, if your program is going to
be called widget, put the main in widget.c.

Consider - if I always put main() in a file named main.c, after 20
years of C programming, I would now have a thousand files named
main.c! How would I remember which was which?


"There is nothing like a main()!
Nothing in the world!"

--
Eric Sosman
es*****@acm-dot-org.invalid
Nov 14 '05 #12

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

Similar topics

4
by: OutsiderJustice | last post by:
Hi All, I can not find any information if PHP support multi-thread (Posix thread) or not at all, can someone give out some information? Is it supported? If yes, where's the info? If no, is it...
37
by: ajikoe | last post by:
Hello, Is anyone has experiance in running python code to run multi thread parallel in multi processor. Is it possible ? Can python manage which cpu shoud do every thread? Sincerely Yours,...
12
by: * ProteanThread * | last post by:
but depends upon the clique: ...
6
by: Joe | last post by:
I have 2 multi-list boxes, 1 displays course categories based on a table called CATEGORIES. This table has 2 fields CATEGORY_ID, CATEGORY_NAME The other multi-list box displays courses based on...
4
by: mimmo | last post by:
Hi! I should convert the accented letters of a string in the correspondent letters not accented. But when I compile with -Wall it give me: warning: multi-character character constant Do the...
5
by: dkelly925 | last post by:
Is there a way to add an If Statement to the following code so if data in a field equals "x" it will launch one report and if it equals "y" it would open another report. Anyone know how to modify...
0
by: Sabri.Pllana | last post by:
We apologize if you receive multiple copies of this call for papers. *********************************************************************** 2008 International Workshop on Multi-Core Computing...
1
by: mknoll217 | last post by:
I am recieving this error from my code: The multi-part identifier "PAR.UniqueID" could not be bound. The multi-part identifier "Salary.UniqueID" could not be bound. The multi-part identifier...
14
by: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= | last post by:
As far as I know, the C Standard has no mention of multi-threaded programming; it has no mention of how to achieve multi-threaded programming, nor does it mention whether the language or its...
4
by: =?Utf-8?B?SGVucmlrIFNjaG1pZA==?= | last post by:
Hi, consider the attached code. Serializing the multi-dimensional array takes about 36s vs. 0.36s for the single-dimensional array. Initializing the multi-dimensional array takes about 4s...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.