M
maxw_cc
Hello everybody,
To express my question, I will help myself
with the following simple snippet
(all functions residing in the same file):
/** stat_fn.c **/
#include <stdio.h>
void foo1(void)
{
void foo2(void);
printf("foo1\n");
foo2();
}
static void foo2(void)
{
printf("foo2\n");
}
int main(void)
{
foo1();
return 0;
}
When I compile it using gcc I get:
$ gcc -g -Wall -ansi -pedantic -o stat_fn stat_fn.c
stat_fn.c:12: warning: `foo2' was declared `extern' and later `static'
And then I thought, maybe changing the declaration for foo2()
withing foo1() to 'static void foo2(void);' would silence the
warning. Then the new file would look like this:
/** stat_fn1.c **/
#include <stdio.h>
void foo1(void)
{
static void foo2(void);
printf("foo1\n");
foo2();
}
static void foo2(void)
{
printf("foo2\n");
}
int main(void)
{
foo1();
return 0;
}
But to my surprise now I got the following:
$ gcc -g -Wall -ansi -pedantic -o stat_fn1 stat_fn1.c
stat_fn1.c: In function `foo1':
stat_fn1.c:5: warning: invalid storage class for function `foo2'
Why is 'static' an invalid storage class for function `foo2' in
the declaration for foo2() embedded in foo1()?
After that I found out, that one way to silence all warnings was to
put the declaration for foo2() at file scope, like this:
/** stat_fn2.c **/
#include <stdio.h>
static void foo2(void);
void foo1(void)
{
printf("foo1\n");
foo2();
}
static void foo2(void)
{
printf("foo2\n");
}
int main(void)
{
foo1();
return 0;
}
And now zero warnings appeared...
Does this mean that I cannot declare a function with the storage
class 'static' if this declaration is local to a function?
What does the standard say about this?
Any light on this matter will be highly appreciated...
Thanks a lot in advance...
Max
To express my question, I will help myself
with the following simple snippet
(all functions residing in the same file):
/** stat_fn.c **/
#include <stdio.h>
void foo1(void)
{
void foo2(void);
printf("foo1\n");
foo2();
}
static void foo2(void)
{
printf("foo2\n");
}
int main(void)
{
foo1();
return 0;
}
When I compile it using gcc I get:
$ gcc -g -Wall -ansi -pedantic -o stat_fn stat_fn.c
stat_fn.c:12: warning: `foo2' was declared `extern' and later `static'
And then I thought, maybe changing the declaration for foo2()
withing foo1() to 'static void foo2(void);' would silence the
warning. Then the new file would look like this:
/** stat_fn1.c **/
#include <stdio.h>
void foo1(void)
{
static void foo2(void);
printf("foo1\n");
foo2();
}
static void foo2(void)
{
printf("foo2\n");
}
int main(void)
{
foo1();
return 0;
}
But to my surprise now I got the following:
$ gcc -g -Wall -ansi -pedantic -o stat_fn1 stat_fn1.c
stat_fn1.c: In function `foo1':
stat_fn1.c:5: warning: invalid storage class for function `foo2'
Why is 'static' an invalid storage class for function `foo2' in
the declaration for foo2() embedded in foo1()?
After that I found out, that one way to silence all warnings was to
put the declaration for foo2() at file scope, like this:
/** stat_fn2.c **/
#include <stdio.h>
static void foo2(void);
void foo1(void)
{
printf("foo1\n");
foo2();
}
static void foo2(void)
{
printf("foo2\n");
}
int main(void)
{
foo1();
return 0;
}
And now zero warnings appeared...
Does this mean that I cannot declare a function with the storage
class 'static' if this declaration is local to a function?
What does the standard say about this?
Any light on this matter will be highly appreciated...
Thanks a lot in advance...
Max