473,230 Members | 1,704 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,230 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 1689
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: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

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.