473,320 Members | 1,821 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,320 software developers and data experts.

static functions in c program file

Hi Everyone,

I had a look at a big project for real-world purpose and i found that
all the functions in c have been prototyped as static and i understand
that this would mean that these functions can be called only from code
within that file, please let me know if there are any other reason to
do this.

Dec 13 '06 #1
7 1884
sa*****@yahoo.co.in wrote:
Hi Everyone,

I had a look at a big project for real-world purpose and i found that
all the functions in c have been prototyped as static
/All/? This seems ... unlikely.

Are all the function /definitions/ marked static? And you did look
in the header files as well, yes?

--
Chris "Perikles triumphant" Dollin
"No-one here is exactly what he appears." G'kar, /Babylon 5/

Dec 13 '06 #2
My gut feeling is that your project are in one single directory and all
the major functions are in one big chunk of code. Static functions are
usually used as what you have indicated in your post. This shall be the
only reason for the other programmers do this.
"sa*****@yahoo.co.in дµÀ£º
"
Hi Everyone,

I had a look at a big project for real-world purpose and i found that
all the functions in c have been prototyped as static and i understand
that this would mean that these functions can be called only from code
within that file, please let me know if there are any other reason to
do this.
Dec 14 '06 #3
zh***********@gmail.com wrote:
"sa*****@yahoo.co.in дµÀ£º
>>
I had a look at a big project for real-world purpose and i found
that all the functions in c have been prototyped as static and i
understand that this would mean that these functions can be called
only from code within that file, please let me know if there are
any other reason to do this.

My gut feeling is that your project are in one single directory and
all the major functions are in one big chunk of code. Static
functions are usually used as what you have indicated in your post.
This shall be the only reason for the other programmers do this.
Please don't top-post. I fixed this one. See the links below.

The fundamental reason is privacy. By declaring the functions
static their names are known only within that compilation unit, and
there is no restriction against reusing the identical names in
another compilation unit. Especially in large projects this avoids
many linking problems.

--
Some informative links:
<news:news.announce.newusers
<http://www.geocities.com/nnqweb/>
<http://www.catb.org/~esr/faqs/smart-questions.html>
<http://www.caliburn.nl/topposting.html>
<http://www.netmeister.org/news/learn2quote.html>
<http://cfaj.freeshell.org/google/>
Dec 14 '06 #4
"CBFalconer" <cb********@yahoo.comwrote in message
news:45***************@yahoo.com...
zh***********@gmail.com wrote:
>"sa*****@yahoo.co.in дµÀ£º
>>>
The fundamental reason is privacy. By declaring the functions
static their names are known only within that compilation unit, and
there is no restriction against reusing the identical names in
another compilation unit. Especially in large projects this avoids
many linking problems.
The real issues tend to be a bit deeper. Each compilation unit is typically
defined to have a well-defined externally-visible interface, and not
separating the interface from the subfunctions tends to lead to a fuzzy way
of thinking and unrestrained connectivity in the software.

Each compilation unit is allowed to interface to the world only in a very
controlled way ... or trouble soon follows.

Dec 14 '06 #5

zh***********@gmail.com wrote:
My gut feeling is that your project are in one single directory and all
the major functions are in one big chunk of code. Static functions are
usually used as what you have indicated in your post. This shall be the
only reason for the other programmers do this.

Hi,

Yes the files are huge and are in a single directory and yes i'm able
to declare the same function in two different files in the same
directory(project) with same name and as staic and it compiles fine.

Thanks everyone for the comments.

Dec 14 '06 #6

zh***********@gmail.com wrote:
My gut feeling is that your project are in one single directory and all
the major functions are in one big chunk of code. Static functions are
usually used as what you have indicated in your post. This shall be the
only reason for the other programmers do this.

Hi,

Yes the files are huge and are in a single directory and yes i'm able
to declare the same function in two different files in the same
directory(project) with same name and as staic and it compiles fine.

Thanks everyone for the comments.

Dec 14 '06 #7

zh***********@gmail.com wrote:
My gut feeling is that your project are in one single directory and all
the major functions are in one big chunk of code. Static functions are
usually used as what you have indicated in your post. This shall be the
only reason for the other programmers do this.

Hi,

Yes the files are huge and are in a single directory and yes i'm able
to declare the same function in two different files in the same
directory(project) with same name and as staic and it compiles fine.

Thanks everyone for the comments.

Dec 14 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Torsten Mohr | last post by:
Hi, i'd like to build an executable file that is linked with a python library and executes a script via PyRun_SimpleString or similar functions. Is there a static library of python available,...
7
by: Nolan Martin | last post by:
is a static functions address constant? ie.. static void func(); write_to_file(&func); Restart program... static void func(); void (*funcPtr) ();
11
by: Peter Salzman | last post by:
I have two files which implement functionality in many of my web pages. Each file uses a function named "parseArguments()" that's critical for each of the two files. I often include both files...
1
by: Jeff | last post by:
Hello everybody, I have a question concerning function declarations. When exactly do you have to declare functions if you want to use them? I have two functions main() and foo(), respectively...
12
by: codefixer | last post by:
Hello: I am trying to understand the use of static in this program. http://nanocrew.net/sw/nscdec.c for "inverse" matrix. What difference would it make if it were not static and just "const...
40
by: vishnu | last post by:
Hi friend, i have a problem in my program what is the use of static function in C lang? plz help me
8
by: Robert A Riedel | last post by:
I have an application that requires a DLL and an executable that uses the DLL, both of which were implemented in Visual C++ using unmanged code. Both the executable and the DLL are linked with...
3
by: llothar | last post by:
I'm using SmallEiffel - which is more or less a huge preprocessor - for C. It has the option to compile the whole Eiffel program into one huge C file but doesn't add a static declaration to the...
10
by: stonny | last post by:
I read the following sentence from a c++ website, but can not understand why. can anyone help me with it? " An important detail to keep in mind when debugging or implementing a program using a...
11
by: Jef Driesen | last post by:
I have the following problem in a C project (but that also needs to compile with a C++ compiler). I'm using a virtual function table, that looks like this in the header file: typedef struct...
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.