468,791 Members | 1,799 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,791 developers. It's quick & easy.

Does filename has to be the same as funtion name??

JS
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
Jul 23 '05 #1
6 1525
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
Jul 23 '05 #2
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.
Jul 23 '05 #3
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
Jul 23 '05 #4
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
Jul 23 '05 #5
In article <d1**********@news.net.uni-c.dk>, JS <sf****@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?
Jul 23 '05 #6

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

Jul 23 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by lkrubner | last post: by
12 posts views Thread by Fred Pacquier | last post: by
10 posts views Thread by Nick L | last post: by
4 posts views Thread by Vikram | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
2 posts views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.