473,396 Members | 2,002 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,396 software developers and data experts.

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 1696
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: lkrubner | last post by:
I want to give users the power to edit files from an easy interface, so I create a form and a PHP script called "fileUpdate". It does a reasonable about of error checking and prints out some...
12
by: Fred Pacquier | last post by:
First off, sorry for this message-in-a-bottle-like post... I haven't been able to phrase my questions well enough to get a meaningful answer from Google in my research. OTOH, it is standard...
6
by: BigDadyWeaver | last post by:
I am using the following code in asp to define a unique and unpredictable record ID in Access. <% 'GENERATE UNIQUE ID Function genguid() Dim Guid guid =...
11
by: BoonHead, The Lost Philosopher | last post by:
I think the .NET framework is great! It's nice, clean and logical; in contradiction to the old Microsoft. It only saddens me that the new Microsoft still doesn't under stand there own...
10
by: Nick L | last post by:
I'm working on a function which creates a pointers to an array of unsigned ints based off a number read from a file. I then continue to read file names from the file, convert the name to a char*...
24
by: Sunner Sun | last post by:
Hi! I have looked through the FAQ but found nothing about it. :-) It seems that this kind of macro is platform dependent, doesn't it? Thank you. Sunner Sun
4
by: Vikram | last post by:
How can i restrict user from entering anything in file name of input type file (upload) control. I want user can ionly select file using browse button
5
by: Lee Xuzhang | last post by:
/* from SICP -- Exercise 4.21: ((lambda (n) ((lambda (fact) (fact fact n)) (lambda (ft k) (if (= k 1) 1 (* k (ft ft (- k 1))))))) 10) */
12
by: TMN | last post by:
Hi All I am new to PHP and I do not understand why the following works ?? $file=urlencode("displayIncidents.php"); echo "<a href=statistics.php?fileName=$file&delete=true>Delete...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.