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

Why can't i make static function

I got 1 set of library, say 'mylib.c' and 'mylib.h'. I define 2
functions (pub_f() and priv_f()) in 'mylib.c' and just declare pub_f()
in 'mylib.h' (i assume the priv_f() is private for that library -
internal use).

Then I create an application, called 'diary.c', and include 'mylib.h'.
but, WHY i still can call the priv_f() function from 'diary.c',
although i don't declare it in 'mylib.h'?

Thanx,

Truely geek :)
Nov 14 '05 #1
2 1150
On 18 Oct 2004 19:36:32 -0700, yo******@gmail.com (Who_Knows_Geek)
wrote in comp.lang.c:
I got 1 set of library, say 'mylib.c' and 'mylib.h'. I define 2
functions (pub_f() and priv_f()) in 'mylib.c' and just declare pub_f()
in 'mylib.h' (i assume the priv_f() is private for that library -
internal use).

Then I create an application, called 'diary.c', and include 'mylib.h'.
but, WHY i still can call the priv_f() function from 'diary.c',
although i don't declare it in 'mylib.h'?

Thanx,

Truely geek :)


If you want to make priv_f() not callable by name from other
translation units (roughly, source files), use the static keyword.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #2
bd
Who_Knows_Geek wrote:
I got 1 set of library, say 'mylib.c' and 'mylib.h'. I define 2
functions (pub_f() and priv_f()) in 'mylib.c' and just declare pub_f()
in 'mylib.h' (i assume the priv_f() is private for that library -
internal use).

Then I create an application, called 'diary.c', and include 'mylib.h'.
but, WHY i still can call the priv_f() function from 'diary.c',
although i don't declare it in 'mylib.h'?

Thanx,

Truely geek :)


If you call a function without a prototype, the compiler assumes it returns
int and takes whatever you gave it. If it turns out it doesn't, the results
are undefined. If you want a function to be only accessible from the file
it was defined in, put 'static' in the definition, like so:

static void priv_f() {
printf("Hello, world!\n");
}
Nov 14 '05 #3

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

Similar topics

12
by: Bryan Parkoff | last post by:
CMain Class is the base class that is initialized in main function. CA Class is the base class that is initialized in CMain::CMain(). CMain Class is always public while CA Class is always...
1
by: Jean-Francois Brault | last post by:
I wrote a crappy class for radian angle management. The class consists of an array of radian values. I put all these things in a class in which all methods are static, so I can access it anywhere...
8
by: SJ | last post by:
Hi: I have a class which has a static member function. The function implements something common to all instances. How can the static member function know all of the (Get access to the instances'...
0
by: Chris F Clark | last post by:
In our C++ project we have some internal bug reporting macros that we use to get useful information when the program does something unexpected. Essentially at the point of the error, we invoke an...
5
by: William Payne | last post by:
Hello, consider the following two classes (parent and child): #ifndef SINGLETON_HPP #define SINGLETON_HPP #include <cstddef> /* NULL */ template <typename T> class Singleton {
8
by: Peter B. Steiger | last post by:
The latest project in my ongoing quest to evolve my brain from Pascal to C is a simple word game that involves stringing together random lists of words. In the Pascal version the whole array was...
10
by: A_StClaire_ | last post by:
hi, I have a singleton Evaluation class that I'm calling repeatedly in one sequence. would someone plz have a look at the code below and tell me if one instance of the singleton can ever...
8
by: Edward Diener | last post by:
By reuse, I mean a function in an assembly which is called in another assembly. By a mixed-mode function I mean a function whose signature has one or more CLR types and one or more non-CLR...
17
by: Juha Nieminen | last post by:
As we know, the keyword "inline" is a bit misleading because its meaning has changed in practice. In most modern compilers it has completely lost its meaning of "a hint for the compiler to inline...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.