gcc-warning

GCC missing braces around initializer

天大地大妈咪最大 提交于 2019-11-29 22:59:01
I have this struct in C below that I want to initialize to all zero. How do I get rid of the missing braces warning? typedef struct { uint32_t incoming[FRAME_TYPE_MAX]; uint32_t outgoing[FRAME_TYPE_MAX]; uint32_t timeouts; uint32_t crc_errors; } pkt_t; static pkt_t stats = {0}; This is GCC bug # 53119: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119 If you want to see it fixed, post a followup to the bug report indicating that it's a problem for you. Since your first member in the structure is an array you need: static pkt_t stats = {{0}}; Outer braces are for the struct, inner braces are

Compile and run program without main() in C

删除回忆录丶 提交于 2019-11-29 19:30:36
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? my code: #include <stdio.h> void nomain() { printf("Hello World...\n"); printf("Successfully run

Why does a “function name” evaluate to true in C and how to get warned on it

泄露秘密 提交于 2019-11-29 13:41:32
问题 I recently stumbled across the following behaviour of gcc 3.2.2 writing a c program: In an if statement I forgot the braces of a function and wrote: if(myFunc)... instead of if(myFunc())... This did not generate an error neither a warning although I have pretty much every warning turned on. It simply evaluated to true . Why is this writing legal code in the first place ? Because the function exists/has an address ? Does anyone know how one could avoid such mistakes or if there is a warning

GCC warning: ISO C does not permit named variadic macros

匆匆过客 提交于 2019-11-29 13:39:58
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 line 76 to 76 #define crumb(phrase0...) printf("") to see if this fixed the warning but with no joy. the

Tell gcc that a function call will not return

依然范特西╮ 提交于 2019-11-29 11:01:13
问题 I am using C99 under GCC . I have a function declared static inline in a header that I cannot modify. The function never returns but is not marked __attribute__((noreturn)) . How can I call the function in a way that tells the compiler it will not return? I am calling it from my own noreturn function, and partly want to suppress the "noreturn function returns" warning but also want to help the optimizer etc. I have tried including a declaration with the attribute but get a warning about the

warning: implicit declaration of function ‘getresuid’ (and ‘seteuid’)

余生长醉 提交于 2019-11-29 08:42:58
I would like to get rid of the warnings. When I compile the source code with gcc -Wall -ansi -o test test.c I get back test.c: In function ‘main’: test.c:12: warning: implicit declaration of function ‘getresuid’ test.c:14: warning: implicit declaration of function ‘seteuid’ When I compile it without -ansi switch gcc -Wall -o test test.c I see on the terminal test.c: In function ‘main’: test.c:12: warning: implicit declaration of function ‘getresuid’ I would like to use -ansi switch and get rid of warnings. How can I achieve my goal ? /* this is the test.c */ #include <stdio.h> #include <sys

How to make gcc warn about returning the address of local variables?

有些话、适合烂在心里 提交于 2019-11-29 06:11:43
With gcc 4.4.5, I have a warning with the following code. char *f(void) { char c; return &c; } But, when I use a temporary pointer, there is no warning anymore (even if the behavior is wrong). char *f(void) { char c; char *p = &c; return p; } I heard that pointer-analysis is difficult in C, but can gcc warn about such code ? Compilers, and most static analyzers, do not try to warn for everything wrong a program might do, because that would entail too many false positives (warnings that do not correspond to actual problems in the source code). Macmade recommends Clang in the comments, a

Remove #pragma once warnings

南楼画角 提交于 2019-11-29 02:36:05
I am using #pragma once in my .cpp s and .hpp s and because of that I get a warning for each file that uses it. I have not found any option to disable this kind of warning, only the thing of #ifndef MY_FILE_H #define MY_FILE_H /*...*/ #endif . So would you recommend me to replace each #pragma once with ifndef s? in header: #define MYFILE_H // all the header and in the other files: #ifndef MYFILE_H #include "myfile.hpp" #endif // the rest of the file What do you think, is it better to use it like this? Or there is an option to disable the #pragma once warnings in GCC, that I do not know?

GCC -Wuninitialized / -Wmaybe-uninitialized issues

旧街凉风 提交于 2019-11-29 01:33:01
I am experiencing a very strange issue using gcc-4.7 (Ubuntu/Linaro 4.7.2-11precise2) 4.7.2 . I am unable to compile the following valid code without a warning: extern void dostuff(void); int test(int arg1, int arg2) { int ret; if (arg1) ret = arg2 ? 1 : 2; dostuff(); if (arg1) return ret; return 0; } Compile options and output: $ gcc-4.7 -o test.o -c -Os test.c -Wall test.c: In function ‘test’: test.c:5:6: warning: ‘ret’ may be used uninitialized in this function [-Wmaybe-uninitialized] However, the following code compiles with no warning (albeit to slightly less efficient assembly): extern

Disable warnings being treated as errors(cc1.exe)

↘锁芯ラ 提交于 2019-11-29 00:42:45
问题 I am developing a brew app. When compiling the app to get MOD file, I am continuously getting this error cc1.exe: warnings being treated as errors I want to disable this warning. I have googled it, and many says disabling -werror will help but I don't know how to do that. The compiler is CodeSourcery ARM. 回答1: You need to remove -Werror from CFLAGS , CPPFLAGS etc.; these are usually set in Makefile's or build scripts. However, I'd strongly advice to fix the actual warnings instead, which will