gcc-warning

How to eliminate external lib/third party warnings in GCC [duplicate]

别说谁变了你拦得住时间么 提交于 2019-11-29 00:06:53
问题 This question already has answers here : How to suppress GCC warnings from library headers? (9 answers) Closed 4 years ago . In the software project I'm working on, we use certain 3rd party libraries which, sadly, produce annoying gcc warnings. We are striving to clean all code of warnings, and want to enable the treat-warnings-as-errors (-Werror) flag in GCC. Is there a way to make these 3rd party generated warnings, which we cannot fix, to disappear? 回答1: I presume you are talking about the

Getting the warning “cast to pointer from integer of different size” from the following code

那年仲夏 提交于 2019-11-28 21:38:57
问题 The code is: Push(size, (POINTER)(GetCar(i) == term_Null()? 0 : 1)); Here is the C code push returns ABC which is typedef POINTER *ABC typedef void * POINTER ABC size; Push(ABC,POINTER); XYZ GetCar(int); typedef struct xyz *XYZ; XYZ term_Null(); long int i; What is the reason for the particular warning? 回答1: You can use intptr_t to ensure the integer has the same width as pointer. This way, you don't need to discover stuff about your specific platform, and it will work on another platform too

Warning: cast to/from pointer from/to integer of different size

烂漫一生 提交于 2019-11-28 20:22:49
I'm learning Pthreads. My code executes the way I want it to, I'm able to use it. But it gives me a warning on compilation. I compile using: gcc test.c -o test -pthread with GCC 4.8.1. And I get the warning test.c: In function ‘main’: test.c:39:46: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] pthread_create(&(tid[i]), &attr, runner, (void *) i); ^ test.c: In function ‘runner’: test.c:54:22: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] int threadnumber = (int) param; ^ This error comes for the following code: #include

Compile and run program without main() in C

℡╲_俬逩灬. 提交于 2019-11-28 15:02:42
问题 I'm trying to compile and run following program without main() function in C . I have compiled my program using the following command. gcc -nostartfiles nomain.c And compiler gives warning /usr/bin/ld: warning: cannot find entry symbol _start; defaulting to 0000000000400340 Ok, No problem. then, I have run executable file(a.out), both printf statements print successfully, and then get segmentation fault . So, my question is, Why segmentation fault after successfully execute print statements?

Why does GCC only sometimes detect the use of a variable before its initialization? [duplicate]

半腔热情 提交于 2019-11-28 11:11:58
This question already has an answer here: Compiler not detecting obviously uninitialized variable 4 answers I was reading some code from a book, when I decided to make a change to see what the uninitialized value of sec would be before the while statement: #include<stdio.h> #define S_TO_M 60 int main(void) { int sec,min,left; printf("This program converts seconds to minutes and "); printf("seconds. \n"); printf("Just enter the number of seconds. \n"); printf("Enter 0 to end the program. \n"); printf("sec = %d\n",sec); while(sec > 0) { scanf("%d",&sec); min = sec/S_TO_M; left = sec % S_TO_M;

GCC warning: ISO C does not permit named variadic macros

白昼怎懂夜的黑 提交于 2019-11-28 07:32:03
问题 Using the following command gcc -c -Wall -Wextra -pedantic -ansi -std=c99 -fstack-protector-all -fstack-check -O3 root.c -o rootTESTOBJECT I get the compiler warning root.h:76:22: warning: ISO C does not permit named variadic macros 72 #ifdef Debug 73 #include <stdio.h> 74 #define crumb(phrase0...) printf(phrase0) 75 #else 76 #define crumb(phrase0...) 77 #endif I believe the option -ansi -std=c99 allows the use of variadic macros, it does according to the docs anyway... I have tried editing

GCC warning about implicit dereference

独自空忆成欢 提交于 2019-11-28 07:20:25
问题 I just ran across the following warning in GCC: warning: implicit dereference will not access object of type ‘volatile util::Yield’ in statement [enabled by default] while compiling this code: volatile util::Yield y1; util::Yield y2; y1 += y2; // <--- Warning triggered here. and unfortunately I do not quite understand what GCC is trying to tell me... The class Yield is declared as follows: class Yield { public: Yield(); Yield &operator+=(Yield const &other); Yield &operator+=(Yield const

Pedantic gcc warning: type qualifiers on function return type

为君一笑 提交于 2019-11-28 06:07:58
When I compiled my C++ code with GCC 4.3 for the first time, (after having compiled it successfully with no warnings on 4.1, 4.0, 3.4 with the -Wall -Wextra options) I suddenly got a bunch of errors of the form warning: type qualifiers ignored on function return type . Consider temp.cpp : class Something { public: const int getConstThing() const { return _cMyInt; } const int getNonconstThing() const { return _myInt; } const int& getConstReference() const { return _myInt; } int& getNonconstReference() { return _myInt; } void setInt(const int newValue) { _myInt = newValue; } Something() :

What is &&& operation in C

女生的网名这么多〃 提交于 2019-11-28 02:58:07
#include <stdio.h> volatile int i; int main() { int c; for (i = 0; i < 3; i++) { c = i &&& i; printf("%d\n", c); } return 0; } The output of the above program compiled using gcc is 0 1 1 With the -Wall or -Waddress option, gcc issues a warning: warning: the address of ‘i’ will always evaluate as ‘true’ [-Waddress] How is c being evaluated in the above program? It's c = i && (&i); , with the second part being redundant, since &i will never evaluate to false . For a user-defined type, where you can actually overload unary operator & , it might be different, but it's still a very bad idea . If

Why is there no gcc/g++ warning for unused temporaries?

二次信任 提交于 2019-11-28 00:07:52
问题 Consider the following code : void ListenerImpl::attach(boost::shared_ptr<ISubscriber> subscriber) { boost::unique_lock<boost::mutex>(mtx); subscribers.push_back(subscriber); } void ListenerImpl::notify(MsgPtr msg) { boost::unique_lock<boost::mutex>(mtx); //notify all subscribers BOOST_FOREACH(boost::shared_ptr<ISubscriber> subscriber, subscribers){ subscriber->update(msg); } } (This is an implementation of an observer pattern as described in GoF.) The user intervention here was to protect