- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Ansi C compiler warning
Operating System - HP-UX
1753516
Members
5304
Online
108795
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
Discussions
Discussions
Forums
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
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
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
тАО04-24-2002 11:55 AM
тАО04-24-2002 11:55 AM
I'm using the Ansi C compiler to build my programs. There is a switch "+w1" which displays additional warnings. This switch is very useful for ensuring prototypes have been used, etc...
However, using this switch with code that contains const always produces the following warning:
"cc: warning 474: By default 'const' qualified objects are now stored in literal space. This may lead to run-time errors if the semantics of 'const' are violated.
Is this an indication of a problem in the code? I don't think it is. If not is there a way to suppress this warning?
However, using this switch with code that contains const always produces the following warning:
"cc: warning 474: By default 'const' qualified objects are now stored in literal space. This may lead to run-time errors if the semantics of 'const' are violated.
Is this an indication of a problem in the code? I don't think it is. If not is there a way to suppress this warning?
Solved! Go to Solution.
- Tags:
- suppress warnings
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-24-2002 12:41 PM
тАО04-24-2002 12:41 PM
Solution
Yes, you can add the +W 474 flag to suppress that warning. You can actually specify a comman separated list of suppressed warning numbers after the '+W' argument.
That warning is telling you that make sure you treat const as const in all files that may contain the specified variable; i.e. don't do anything in another source file to change it's value.
That warning is telling you that make sure you treat const as const in all files that may contain the specified variable; i.e. don't do anything in another source file to change it's value.
If it ain't broke, I can fix that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-04-2002 01:08 PM
тАО06-04-2002 01:08 PM
Re: Ansi C compiler warning
This can actually be a warning that requires a coding change. It came up in the course of a code migration that we're going through, and I wrote the following to the other people on the project:
Apparently, the 11.0 compiler will treat some literals as variables of type const even if you don't explicitly declare them as such, but it will do so in a way that takes effect at execution time only: rather than terminating the compilation, the compiler simply issues a warning
By default 'const' qualified objects are now stored in literal space using 474. This may lead to run-time errors if the semantics of 'const' are violated
and then when "the semantics of 'const' are violated" you get a bus error. Not a core dump, just a bus error. (To make the warning even more helpful, it doesn't always appear, and when it does there's no line number associated with it.).
The only good thing about the problem is that it only seems to arise with code of a sort that I hope doesn't get written very much. For example:
#include
#include
main(int argc, char *argv[])
{
void OverlayLiteral(char *);
OverlayLiteral("ORIGINALSTRING");
return(EXIT_SUCCESS);
}
void OverlayLiteral(char * arg)
{
sprintf(arg,"%s","NEWSTRING");
printf("arg is %s\n",arg);
}
On 11.0, the sprintf marked in red will trigger a bus error, even though it will execute without any problem on 10.2 and fall through to print "arg is NEWSTRING". Apparently, 11.0 saves "ORIGINALSTRING" in some kind of protected location.
Apparently, the 11.0 compiler will treat some literals as variables of type const even if you don't explicitly declare them as such, but it will do so in a way that takes effect at execution time only: rather than terminating the compilation, the compiler simply issues a warning
By default 'const' qualified objects are now stored in literal space using 474. This may lead to run-time errors if the semantics of 'const' are violated
and then when "the semantics of 'const' are violated" you get a bus error. Not a core dump, just a bus error. (To make the warning even more helpful, it doesn't always appear, and when it does there's no line number associated with it.).
The only good thing about the problem is that it only seems to arise with code of a sort that I hope doesn't get written very much. For example:
#include
#include
main(int argc, char *argv[])
{
void OverlayLiteral(char *);
OverlayLiteral("ORIGINALSTRING");
return(EXIT_SUCCESS);
}
void OverlayLiteral(char * arg)
{
sprintf(arg,"%s","NEWSTRING");
printf("arg is %s\n",arg);
}
On 11.0, the sprintf marked in red will trigger a bus error, even though it will execute without any problem on 10.2 and fall through to print "arg is NEWSTRING". Apparently, 11.0 saves "ORIGINALSTRING" in some kind of protected location.
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.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP