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

J

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
 
T

Thomas Matthews

JS said:
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
 
V

Victor Bazarov

JS said:
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
 
R

Rune Bromer

JS said:
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.
 
M

Mads Jensen

JS said:
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,
 
G

Greg Comeau

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.
 
D

Default User

Thomas said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top