On 2014-03-12, SAHIL MAHLA <(E-Mail Removed)> wrote:
> Hi Experts,
Hi Sahil,
I'm glad you're reading the FAQ.
> Could you explain what does they mean by "The implicit external function
> declaration that can occur when a function is called does not help when a
> function name's only use is for its value." -in ques 1.34 C-faq
An external function declaration is a function declaration which has
external linkage:
static int foo(void); /* internal declaration */
int bar(void); /* external declaration */
An implicit declaration occurs when your program contains the syntax
of a function call, but whose identifier isn't declared anywhere.
For instance, suppose that a declaration for foo hasn't been
seen previously, and we have this:
int x = foo("abc");
in this situation, an implicit declaration is supplied: an unwritten, invisible
declaration that exists in the "mind" of the compiler, so to speak. The
language implementation proceeds on the assumption that foo is a function.
(This is very unsafe: we have no idea whether or not foo can be called with a
string argument, or whether or not it returns int.)
The FAQ question is stating somewhat clumsily that this implicit declaration
logic does not kick in if the function is only referenced to obtain the
function pointer as a value. For instance:
int (*ptr)(char *) = foo;
Here, if foo has not been declared, it will not be implicitly declared as a
function because it's not used to express a function call. This is simply a
diagnosable error: foo is an undeclared identifier.
This is the case even though the context makes it clear that foo is probably a
function pointer or a function, just like the context foo("abc").
(Some languages are deeply based on inference: programs require few
declarations, because the information propagates implicitly through the program
by logical inferences which follow the data flows.)
--
Music DIY Mailing List: http://www.kylheku.com/diy
ADA MP-1 Mailing List: http://www.kylheku.com/mp1
> Hi Experts,
Hi Sahil,
I'm glad you're reading the FAQ.
> Could you explain what does they mean by "The implicit external function
> declaration that can occur when a function is called does not help when a
> function name's only use is for its value." -in ques 1.34 C-faq
An external function declaration is a function declaration which has
external linkage:
static int foo(void); /* internal declaration */
int bar(void); /* external declaration */
An implicit declaration occurs when your program contains the syntax
of a function call, but whose identifier isn't declared anywhere.
For instance, suppose that a declaration for foo hasn't been
seen previously, and we have this:
int x = foo("abc");
in this situation, an implicit declaration is supplied: an unwritten, invisible
declaration that exists in the "mind" of the compiler, so to speak. The
language implementation proceeds on the assumption that foo is a function.
(This is very unsafe: we have no idea whether or not foo can be called with a
string argument, or whether or not it returns int.)
The FAQ question is stating somewhat clumsily that this implicit declaration
logic does not kick in if the function is only referenced to obtain the
function pointer as a value. For instance:
int (*ptr)(char *) = foo;
Here, if foo has not been declared, it will not be implicitly declared as a
function because it's not used to express a function call. This is simply a
diagnosable error: foo is an undeclared identifier.
This is the case even though the context makes it clear that foo is probably a
function pointer or a function, just like the context foo("abc").
(Some languages are deeply based on inference: programs require few
declarations, because the information propagates implicitly through the program
by logical inferences which follow the data flows.)
--
Music DIY Mailing List: http://www.kylheku.com/diy
ADA MP-1 Mailing List: http://www.kylheku.com/mp1
Aucun commentaire:
Enregistrer un commentaire