| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"JS" |
| Date: |
14 Mar 2005 11:24:52 AM |
| Object: |
Does filename has to be the same as funtion name?? |
I am writing som C code and was wondering if I should call the filename the
same as the name of my function. It compiles ok but should I make a file for
each funtion just to keep it orderly or is there no tradition for this?
JS
.
|
|
| User: "Greg Comeau" |
|
| Title: Re: Does filename has to be the same as funtion name?? |
14 Mar 2005 03:23:29 PM |
|
|
In article <d14h03$feh$1@news.net.uni-c.dk>, JS <sfsdfs@asdas.com> wrote:
I am writing som C code
This is a C++ NG not a C one, so some thing are different, but anyway...
and was wondering if I should call the filename the
same as the name of my function. It compiles ok but should I make a file for
each funtion just to keep it orderly or is there no tradition for this?
That's one way do it, and should probably normally be your starting
point for external global functions.
Another way is to group "like functions", especially if they
are say static or refer to each other or something like that.
As with all things there is compromises to consider.
I would suggest getting Stroustrup's 3rd edition (or his spccial
edition) and checking out Chapter 9 for many issues such as this.
--
Greg Comeau / Comeau for the Mac? Stay tuned.
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
.
|
|
|
|
| User: "Victor Bazarov" |
|
| Title: Re: Does filename has to be the same as funtion name?? |
14 Mar 2005 11:40:16 AM |
|
|
JS wrote:
I am writing som C code
And why are you in a C++ newsgroup? There is comp.lang.c, you know...
and was wondering if I should call the filename the
same as the name of my function. It compiles ok but should I make a file for
each funtion just to keep it orderly or is there no tradition for this?
No. Name them as you wish. Place more than one function in a file as
it suits you.
V
.
|
|
|
|
| User: "Thomas Matthews" |
|
| Title: Re: Does filename has to be the same as funtion name?? |
14 Mar 2005 11:39:50 AM |
|
|
JS wrote:
I am writing som C code and was wondering if I should call the filename the
same as the name of my function. It compiles ok but should I make a file for
each funtion just to keep it orderly or is there no tradition for this?
JS
This is a style issue.
If you maintain one function per file, then you have
a good system. However, if you encapsulate many functions
in a file, I would name the file by theme.
Be aware that there is a file reading efficiency issue.
I would not create separate files for one line functions.
There is a minimum amount of lines for which the file opening
and closing time is greater than the time to read the contents.
--
Thomas Matthews
C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library
.
|
|
|
| User: "Default User" |
|
| Title: Re: Does filename has to be the same as funtion name?? |
14 Mar 2005 06:23:19 PM |
|
|
Thomas Matthews wrote:
JS wrote:
I am writing som C code and was wondering if I should call the
filename the
same as the name of my function. It compiles ok but should I make a
file for
each funtion just to keep it orderly or is there no tradition for
this?
This is a style issue.
If you maintain one function per file, then you have
a good system.
I would diagree with that for C, which he asked about, as that would
require all functions to be externally linked.
However, if you encapsulate many functions
in a file, I would name the file by theme.
The "one class" rule is pretty popular in C++. That is, one
header/implementation file per class.
Brian
.
|
|
|
|
|
| User: "Rune Bromer" |
|
| Title: Re: Does filename has to be the same as funtion name?? |
14 Mar 2005 11:41:04 AM |
|
|
JS wrote:
I am writing som C code and was wondering if I should call the filename the
same as the name of my function. It compiles ok but should I make a file for
each funtion just to keep it orderly or is there no tradition for this?
JS
Well it's up to you. Normaly I group functions in a file. As an example
I would put all functions regarding points in a grid in coord.cc or
something like that.
.
|
|
|
|
| User: "Mads Jensen" |
|
| Title: Re: Does filename has to be the same as funtion name?? |
14 Mar 2005 12:57:16 PM |
|
|
JS wrote:
I am writing som C code and was wondering if I should call the filename the
same as the name of my function. It compiles ok but should I make a file for
each funtion just to keep it orderly or is there no tradition for this?
I'll answer your question, even though it's about C (unless you forgot
the plusses ? :-))
Do as you please :-) There are no rules whatsoever in how to organize
your functions in various files. It might be a good idea, though, so
that you don't have to look in lots of files to find the definition of a
function you used in another function. An idea would be to organize your
functions in files, so that each file has functions for doing specific
parts of a program. That's how I'd do it, and it seems that others are
doing this, too.
FUT: comp.lang.c
Sincerely,
--
Mads Jensen - remove z's in email
If the code and the comments disagree, then both
are probably wrong. -- Norm Schryer
.
|
|
|
|

|
Related Articles |
|
|