Methods for removing specific warnings in GCC or clang

Source: Internet
Author: User

Generally, a considerable amount of warning information is generated during code compilation, especially when the-wall option is used. -Wall does not open all warnings as it literally means. however, it has opened a lot of warnings. we can certainly block warnings that we know are "harmless" but still print out to occupy poor console space.

Take the following code for example:

#include <stdio.h>#include <stdlib.h>#include <stdbool.h>#include <unistd.h>int main(void){long double ld = 10000.2222L;puts("hello world!???(y/n)");printf("long double type size is %lu %lu\n",sizeof(long double),sizeof ld);return 0;}

It generates a warning for the so-called "three character group symbol". If this is exactly what we need, we can ignore this warning. let's compile it to see first (whether using GCC or clang ):

GCC:

[email protected]:~/src/c_src$ gcc -Wall -std=c11 -O3 -g0 -s -o x x.cx.c: In function ‘main’:x.c:9:21: warning: trigraph ??( converted to [ [-Wtrigraphs]  puts("hello world!???(y/n)"); ^

Clang:

[email protected]:~/src/c_src$ clang -Wall -std=c11 -O3 -g0 -s -o x x.cx.c:9:21: warning: trigraph converted to '[' character [-Wtrigraphs]        puts("hello world!???(y/n)");                           ^1 warning generated.

However, after removing the-Wall warning, you can find that there is no warning and everything is quiet. however, this is not what we want, because some warnings that truly imply error classes may be missed. you can see that the warning type is-wtrigraphs. we only need to add no after W to block this warning, but we need to put it behind the wall option. If we put it above, there will still be a warning. the compiler should be based on the last "valid" option!

[email protected]:~/src/c_src$ gcc -Wall -Wno-trigraphs -std=c11 -O3 -g0 -s -o x x.c




Methods for removing specific warnings in GCC or clang

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.