In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Xiaobian to share with you what are not commonly used in linux gcc command line options, I believe most people do not know how, so share this article for everyone's reference, I hope you have a lot of harvest after reading this article, let's go to understand it together!
Generate warnings not included with the-Wall option
Although the gcc compiler's-Wall option covers most warning flags, there are still warnings that cannot be generated. To generate them, use the-Wextra option.
For example, the following code:
#include #include int main() { int i=0; /* ... some code here ... */ if(i); return 1; return 0; }
I accidentally typed an extra semicolon after the if condition. Now, if you compile using the following gcc command, no warnings are generated.
gcc -Wall test.c -o test
But if you also compile with the-Wextra option:
gcc -Wall -Wextra test.c -o test
A warning such as the following is generated:
test.c: In function ‘main’: test.c:10:8: warning: suggest braces around empty body in an ‘if’ statement [-Wempty-body] if(i);
As is clear from the warning above, the-Wextra option internally enables the-Wempty-body option to detect suspicious code and generate warnings. Below are all warning flags enabled for this option.
-Wclobbered
-Wempty-body
-Wignored-qualifiers
-Wmissing-field-initializers
-Wmissing-parameter-type (C only)
-Wold-style-declaration (C only)
-Woverride-init
-Wsign-compare
-Wtype-limits
-Wuninitialized
-Wunused-parameter (enabled only if and-Wunused or-Wall options are used)
-Wunused-but-set-parameter (generated only if and-Wunused or-Wall`options are used)
If you want to know more about the tags mentioned above, please check the gcc manual.
In addition, the-Wextra option also generates warnings in the following cases:
A pointer is compared with the integer 0 =
(C++ only) An enumerated type and a nonenumerated type appear simultaneously in a conditional expression
(C++ only) Ambiguous virtual bases
(C++ only) subscript array of register types
(C++ only) Addresses register-type variables
(C++ only) Base class not initialized in copy constructor of derived class
Generate warnings when comparing equivalents of floating point values
You probably already know that floating-point values cannot be compared exactly for equality (if not, read the FAQ on floating-point value comparisons). But if you accidentally do, does the gcc compiler give you an error or warning? Let's test it:
Here's a snippet of code that uses the == operator for floating-point value comparisons:
#include void compare(float x, float y) { if(x == y) { printf("\n EQUAL \n"); } } int main(void) { compare(1.234, 1.56789); return 0; }
Use the following gcc command (with the-Wall and-Wextra options) to compile this code:
gcc -Wall -Wextra test.c -o test
Unfortunately, the above command does not generate any warnings related to floating-point value comparisons. A quick look at the gcc manual shows that a special-Wfloat-equal option is available in this case.
Here are the commands that include this option:
gcc -Wall -Wextra -Wfloat-equal test.c -o test
Here is the output from this command:
test.c: In function ‘compare’: test.c:5:10: warning: comparing floating point with == or != is unsafe [-Wfloat-equal] if(x == y)
As you can see in the output above, the-Wfloat-equal option forces the gcc compiler to generate a warning about floating-point value comparisons.
Here is the gcc manual for this option:
The idea behind this is that sometimes it is convenient for programmers to think of floating point values as approximate *** exact real numbers. If you do this, then you need to figure out the *** or possible *** error introduced by this calculation by analyzing the code, or by other means, and then allow this error when comparing (and when producing the output, but this is a different problem). In particular, you should not check for equality, but for possible range overlap between two values; this is done with relational operators, so the equivalence comparison may be a mistake.
How to better manage gcc command line options
If the list of command-line options becomes large and difficult to manage in your gcc command, you can put it in a text file and use the filename as an argument to the gcc command. After that, you must use the @file command line option.
For example, here is your gcc command:
gcc -Wall -Wextra -Wfloat-equal test.c -o test
You can then put these three warning-related options into a file called gcc-options:
$ cat gcc-options -Wall -Wextra -Wfloat-equal
This way, your gcc commands will be simpler and easier to manage:
gcc @gcc-options test.c -o test
Here are the gcc manual instructions for @file:
Read command line options from file. The option read is inserted in the same place as the original @file option. If the file does not exist or cannot be read, this option is treated as word processing and not deleted.
Options in the file are separated by spaces. If an option contains white space characters, you can enclose the entire option in single or double quotes. Any character (including backslashes: '\') may be included in an option with a'\'prefix. If the file itself contains an additional @file option, it will be processed recursively.
The above is "linux is not commonly used gcc command line options what" all the content of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.