HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- static in front of function declared locally
Operating System - HP-UX
1828360
Members
3299
Online
109976
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2003 11:17 AM
06-30-2003 11:17 AM
static in front of function declared locally
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
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
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
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
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
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
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
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2003 11:47 AM
06-30-2003 11:47 AM
Re: static in front of function declared locally
hi Max,
It's mostly because you are using the ansi switch. "True ansi" requires you to declare all functions extern or static but will default to extern, assuming there might be an include file declaring the function. I believe if you ran your program thru "lint" , you would be flooded with warnings about all functions not declared at the top of your program.
It's mostly because you are using the ansi switch. "True ansi" requires you to declare all functions extern or static but will default to extern, assuming there might be an include file declaring the function. I believe if you ran your program thru "lint" , you would be flooded with warnings about all functions not declared at the top of your program.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2003 11:08 AM
07-01-2003 11:08 AM
Re: static in front of function declared locally
I think its okay to declare a function static in a local context.
The problem is that you need to remove the forward reference too foo2 in foo1 and everything should run okay.
The problem is that you need to remove the forward reference too foo2 in foo1 and everything should run okay.
The sufficiency of my merit is to know that my merit is NOT sufficient
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2003 11:48 AM
07-01-2003 11:48 AM
Re: static in front of function declared locally
After doing some reading I found that ISO C99
standard makes a pretty clear point of it:
6.7.1 Storage-class specifiers
...
5 The declaration of an identifier for a function that has block scope shall have no explicit storage-class specifier other than extern.
...
Thanks anyway...
standard makes a pretty clear point of it:
6.7.1 Storage-class specifiers
...
5 The declaration of an identifier for a function that has block scope shall have no explicit storage-class specifier other than extern.
...
Thanks anyway...
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Support
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP