Re: FAQ 1.12--auto keyword
- From: "Bill Pursell" <bill.pursell@xxxxxxxxx>
- Date: 10 Apr 2006 11:13:02 -0700
Richard Bos wrote:
"Bill Pursell" <bill.pursell@xxxxxxxxx> wrote:
The faq (question 1.12) states that the keyword "auto" is completely
useless.
However, it is necessary to forward declare a nested function (for
gcc...I'm not sure if this is gcc specific or a language issue.)
There is no such thing as a nested function in ISO C.
If gcc allows nested functions, that's its business. However, if it
requires "auto" to forwardly declare them, this is broken. They should
have chosen "static".
Actually, I'm thinking the entire nested function idea is broken. When
I first saw it, I thought it was a neat idea, but I quickly changed my
impression of it to "interesting curiosity". I now consider it
completely pointless. But it does raise a question for me.
If I want to get the same behavior as a nested function (and as
far as I can tell, all it gives you is the ability to have 2 different
functions with the same name in the same linkage unit), I
could do this:
#include <stdio.h>
static int
func0(int x)
{
return x;
}
static int
func1(int x)
{
return x +1;
}
static int
foo0(int x)
{
static int(*const func)(int) = func0;
return func(x);
}
static int
foo1(int x)
{
static int(*const func)(int) = func1;
return func(x);
}
int
main(void)
{
printf("%d\n", foo0(0));
printf("%d\n", foo1(0));
}
So both foo0() and foo1() can use the name "func" to
reference different functions. Now, my question is:
is this as efficient as coding it so that foo{i} calls func{i}
directly? It seems like there may be any extra step involved.
Is there a way I could code it so that the two are certainly
identical? I'm declaring each as const within foo to
try to make that happen, but I suspect it doesn't really
help.
.
- Follow-Ups:
- Re: FAQ 1.12--auto keyword
- From: CBFalconer
- Re: FAQ 1.12--auto keyword
- From: Ben Pfaff
- Re: FAQ 1.12--auto keyword
- From: Vladimir S. Oka
- Re: FAQ 1.12--auto keyword
- From: Keith Thompson
- Re: FAQ 1.12--auto keyword
- References:
- FAQ 1.12--auto keyword
- From: Bill Pursell
- Re: FAQ 1.12--auto keyword
- From: Richard Bos
- FAQ 1.12--auto keyword
- Prev by Date: Re: How to read strings from a file with comments
- Next by Date: Re: How to read strings from a file with comments
- Previous by thread: Re: FAQ 1.12--auto keyword
- Next by thread: Re: FAQ 1.12--auto keyword
- Index(es):
Relevant Pages
|