gcc-warning

GCC: How to customising warning and errors generated from compilation

时光怂恿深爱的人放手 提交于 2021-02-11 12:51:38
问题 My Usecase: I have two c language files: ApplicationCode.c and UserCode.c . Application code is something generated by my app and UserCode is available to my application user where he can write his own code. ApplicationCode.c internally uses UserCode.c and calls out its methods/function. One thing you can assume here that ApplicationCode.c will never have any errors but could have warnings generated by gcc compiler. And UserCode.c can have both errors and warnings. So, While compiling code I

implicit declaration warning: What are the built-in functions?

£可爱£侵袭症+ 提交于 2021-02-08 07:44:59
问题 The question-asking interface is flagging many "Questions that may already have your answer", but I have attempted to do due diligence to check if any are asking exactly what I am here. My apologies if this is a duplicate. Suppose I have the following incorrect program: extern void undefined_function(void); int main(int argc, char **argv) { undefined_function(); undeclared_function(); exit(0); } Compiling with gcc gives: $ gcc warnings.c warnings.c: In function ‘main’: warnings.c:6:2: warning

Report warning when apply container_of macro to embedded char array

假如想象 提交于 2021-02-08 05:39:38
问题 When I apply container_of macro to a C struct which contains an array of char, I got warning: initialization from incompatible pointer type . Here is the codes: #define container_of(ptr, type, member) ({ \ const typeof( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr - offsetof(type,member) );}) struct st { int a; char b; char c[16]; void *p; }; int main(void) { struct st t = { .a = 101, .b = 'B', .c = "hello", .p = NULL }; char (*p)[16] = &t.c; struct st *s = container_of(p

How do I disable a gcc warning which has no command line switch?

不羁岁月 提交于 2021-02-07 11:44:05
问题 I get the following warning: warning: 'X' is initialized and declared 'extern' and it looks like it's no big deal and I could disable it. Changing the code is not really a good idea in my case because I have no control over the code, I just need to compile it. So I want to disable the warning. If it had a -WSomeDefect key next to it then I could use a -Wno-SomeDefect command line switch but it looks like there's no distinct switch for this warning. How do I disable such warning? 回答1: For a

GCC no longer implements <varargs.h>

家住魔仙堡 提交于 2021-02-07 06:28:08
问题 I have to change this code fragment from varargs.h to stdarg.h, but I do not know exactly how to: #ifndef lint int ll_log (va_alist) va_dcl { int event, result; LLog *lp; va_list ap; va_start (ap); lp = va_arg (ap, LLog *); event = va_arg (ap, int); result = _ll_log (lp, event, ap); va_end (ap); return result; } When I try build this, compiler says: error "GCC no longer implements <varargs.h>." error "Revise your code to use <stdarg.h>." The program, which I need to compile and run, has a few

Unexpected gcc warning: function returns address of local variable - is it a compiler bug?

会有一股神秘感。 提交于 2021-01-28 05:20:52
问题 Following is the minimum working example (ok, in fact it's minimum non-working example :-)). When compiled with gcc (from version 5.0 up to 9.3) it fires the following warning. It even seems to fire the warning only in release build ( -02 and higher). Code: class A { }; class B { const A& getA() const { static A a; return a; } const A& get(bool b) const; }; const A& B::get(bool b) const { return static_cast<const A&>(b ? getA() : getA()); } int main(int argc, char** argv) { return 0; }

gcc size_t and sizeof arithmetic conversion to int

梦想的初衷 提交于 2020-11-29 07:19:52
问题 I decided to test compile a project with -Wsign-conversion enabled, to see what warnings would come up, and came across something that doesn't seem right, where gcc behaves differently than clang. Can someone please tell me which is correct? I have a function that takes a size_t param: void func(size_t) {} some other struct struct Test {}; and calling code int i = some_initialiser(); func(sizeof(Test) + static_cast<size_t>(i)); So from my understanding, sizeof returns size_t , and arithmetic

gcc size_t and sizeof arithmetic conversion to int

こ雲淡風輕ζ 提交于 2020-11-29 07:19:12
问题 I decided to test compile a project with -Wsign-conversion enabled, to see what warnings would come up, and came across something that doesn't seem right, where gcc behaves differently than clang. Can someone please tell me which is correct? I have a function that takes a size_t param: void func(size_t) {} some other struct struct Test {}; and calling code int i = some_initialiser(); func(sizeof(Test) + static_cast<size_t>(i)); So from my understanding, sizeof returns size_t , and arithmetic

gcc size_t and sizeof arithmetic conversion to int

这一生的挚爱 提交于 2020-11-29 07:18:22
问题 I decided to test compile a project with -Wsign-conversion enabled, to see what warnings would come up, and came across something that doesn't seem right, where gcc behaves differently than clang. Can someone please tell me which is correct? I have a function that takes a size_t param: void func(size_t) {} some other struct struct Test {}; and calling code int i = some_initialiser(); func(sizeof(Test) + static_cast<size_t>(i)); So from my understanding, sizeof returns size_t , and arithmetic

expected expected ‘const char **’ but argument is of type ‘char **’

安稳与你 提交于 2020-11-27 19:42:55
问题 Here is the compile warning i have: src/Debugger.c:219:52: warning: passing argument 2 of ‘Debugger_Command[i].Callback’ from incompatible pointer type Debugger_Command[i].Callback(argc, argv); ^ src/Debugger.c:219:52: note: expected ‘const char **’ but argument is of type ‘char **’ Here is the relevant source code: /* Definition */ typedef void (*Debugger_Callback_t)(int argc, char const * argv[]); typedef struct tagDebugger_Command_t { /* ... */ Debugger_Callback_t Callback; /**< Callback *