Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > multi-file programs - main.c recommended?

Reply
Thread Tools

multi-file programs - main.c recommended?

 
 
G Patel
Guest
Posts: n/a
 
      03-03-2005
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).

 
Reply With Quote
 
 
 
 
G Patel
Guest
Posts: n/a
 
      03-03-2005
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).


 
Reply With Quote
 
 
 
 
Jens.Toerring@physik.fu-berlin.de
Guest
Posts: n/a
 
      03-03-2005
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).


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 ___
\__________________________ http://www.toerring.de
 
Reply With Quote
 
Rouben Rostamian
Guest
Posts: n/a
 
      03-03-2005
In article <. com>,
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).


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
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      03-03-2005
"G Patel" <> 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) kst- <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.
 
Reply With Quote
 
Harshal
Guest
Posts: n/a
 
      03-03-2005
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).


 
Reply With Quote
 
Parahat Melayev
Guest
Posts: n/a
 
      03-03-2005
"G Patel" <> wrote in message news:< 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
 
Reply With Quote
 
Alan Balmer
Guest
Posts: n/a
 
      03-03-2005
On 2 Mar 2005 17:14:49 -0800, "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).


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

 
Reply With Quote
 
Kiru Sengal
Guest
Posts: n/a
 
      03-03-2005
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
.
.
.
.../[Program n-1 name]/main.c
.../[Program n name]/main.c


Even though I rarely use 'main.c' myself, doing so shouldn't limit
someone's ability to 'remember'(recognize) the the program it belongs
to. Keith also stated a case where 'main.c' should be avoided, but I
don't think that applies here.

 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      03-03-2005
Alan Balmer <> 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) kst- <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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
EDA, PCB, Mentor Graphics programs 2006 - , programs, ola8@mail.gr VHDL 0 05-31-2006 08:07 PM
retrieveing programs deleted in add or remove programs in control panel truebluedave Computer Support 2 08-23-2005 10:32 PM
Programs take a long time to launch from A.Programs Me MCSE 9 01-20-2005 04:05 PM
compile C programs with UNIX system calls (= Unix Programs??) jrefactors@hotmail.com C++ 12 01-10-2005 03:35 AM
Re: How to see all programs after Start -> All Programs Ben Leal Computer Support 1 08-06-2003 01:58 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57