Re: allowing a function to be called only from a specific function
- From: CBFalconer <cbfalconer@xxxxxxxxx>
- Date: Thu, 30 Nov 2006 23:45:33 -0500
Harald van D?k wrote:
CBFalconer schreef:
Harald van D?k wrote:
CBFalconer wrote:... snip ...
Yes it can. The 'static' only prevents visibility outside the
compilation unit.
No, it cannot. f3 is defined before f1 is declared. You can refer
to a static function or variable with an extern declaration if and
only if the a static declaration is already in scope, and you
cannot use static on a function declaration with block scope.
Counter example. Nothing says you have to heed warnings. Proper
isolation requires a separate source file.
[1] c:\c\junk>cat junk.c
#include <stdio.h>
int main(void) {
void f1(void);
f1();
return 0;
} /* main */
static void f1(void) {
puts("In f1");
}
[1] c:\c\junk>cc junk.c
junk.c:10: warning: `f1' was declared `extern' and later `static'
[1] c:\c\junk>.\a
In f1
That's nice. As far as standard C is concerned, the behaviour is
undefined per 6.2.2p7, and my compiler rejects it. If you count
implementation-specific extensions, then inline assembly may also allow
you to access static functions defined in another source file.
Then try this:
#include <stdio.h>
static void f1(void);
int main(void) {
f1();
return 0;
} /* main */
static void f1(void) {
puts("In f1");
}
--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
.
- Follow-Ups:
- Re: allowing a function to be called only from a specific function
- From: Harald van Dijk
- Re: allowing a function to be called only from a specific function
- References:
- allowing a function to be called only from a specific function
- From: junky_fellow@xxxxxxxxxxx
- Re: allowing a function to be called only from a specific function
- From: Richard Heathfield
- Re: allowing a function to be called only from a specific function
- From: junky_fellow@xxxxxxxxxxx
- Re: allowing a function to be called only from a specific function
- From: mark_bluemel
- Re: allowing a function to be called only from a specific function
- From: Chris Dollin
- Re: allowing a function to be called only from a specific function
- From: Old Wolf
- Re: allowing a function to be called only from a specific function
- From: Harald van Dijk
- Re: allowing a function to be called only from a specific function
- From: CBFalconer
- Re: allowing a function to be called only from a specific function
- From: Harald van Dijk
- Re: allowing a function to be called only from a specific function
- From: CBFalconer
- Re: allowing a function to be called only from a specific function
- From: Harald van Dijk
- allowing a function to be called only from a specific function
- Prev by Date: Re: atol of a value > INT_MAX
- Next by Date: Re: void * to struct * casting ..please help!
- Previous by thread: Re: allowing a function to be called only from a specific function
- Next by thread: Re: allowing a function to be called only from a specific function
- Index(es):
Relevant Pages
|