gcc-warning

How to make gcc warn about passing wrong enum to a function

时光总嘲笑我的痴心妄想 提交于 2019-11-26 08:28:57
问题 gcc doesn\'t seem to produce a warning with the following code. How can I get it to produce a warning? typedef enum { REG8_A, REG8_B, REG8_C }REG8; typedef enum { REG16_A, REG16_B, REG16_C }REG16; void function(REG8 reg8) { } int main(void) { function(REG16_A); // Should warn about wrong enum } 回答1: The reason of such behaviour is that you are using C compiler rather than C++. And in C enum types are not really types, enums in C just hold int constants and they can be freely mixed with

warning: incompatible implicit declaration of built-in function ‘xyz’

蹲街弑〆低调 提交于 2019-11-26 04:07:57
问题 I\'m getting a number of these warnings when compiling a few binaries: warning: incompatible implicit declaration of built-in function ‘strcpy’ warning: incompatible implicit declaration of built-in function ‘strlen’ warning: incompatible implicit declaration of built-in function ‘exit’ To try to resolve this, I have added #include <stdlib.h> at the top of the C files associated with this warning, in addition to compiling with the following flags: CFLAGS = -fno-builtin-exit -fno-builtin

How to turn on (literally) ALL of GCC&#39;s warnings?

陌路散爱 提交于 2019-11-26 04:06:45
问题 I would like to enable -- literally -- ALL of the warnings that GCC has. (You\'d think it would be easy...) You\'d think -Wall might do the trick, but nope! Still need -Wextra . You\'d think -Wextra might do the trick, but nope! Not all of the warnings listed here (for example, -Wshadow ) are enabled by this. And I still have no idea if this list is comprehensive. How do I tell GCC to enable (no if\'s, and\'s, or but\'s!) all the warnings it has? 回答1: You can't. The manual for GCC 4.4.0 is

How to suppress “unused parameter” warnings in C?

我只是一个虾纸丫 提交于 2019-11-26 03:48:52
问题 For instance: Bool NullFunc(const struct timespec *when, const char *who) { return TRUE; } In C++ I was able to put a /*...*/ comment around the parameters. But not in C of course, where it gives me the error error: parameter name omitted . 回答1: I usually write a macro like this: #define UNUSED(x) (void)(x) You can use this macro for all your unused parameters. (Note that this works on any compiler.) For example: void f(int x) { UNUSED(x); ... } 回答2: In gcc, you can label the parameter with

What&#39;s a proper way of type-punning a float to an int and vice-versa?

旧街凉风 提交于 2019-11-26 03:25:29
问题 The code below performs a fast inverse square root operation by some bit hacks. The algorithm was probably developed by Silicon Graphics in early 1990\'s and it\'s appeared in Quake 3 too. more info However I get the following warning from GCC C++ compiler : dereferencing type-punned pointer will break strict-aliasing rules Should I use static_cast , reinterpret_cast or dynamic_cast instead in such situations? float InverseSquareRoot(float x) { float xhalf = 0.5f*x; int32_t i = *(int32_t*)&x;

How do I best silence a warning about unused variables?

回眸只為那壹抹淺笑 提交于 2019-11-26 00:51:51
问题 I have a cross platform application and in a few of my functions not all the values passed to functions are utilised. Hence I get a warning from GCC telling me that there are unused variables. What would be the best way of coding around the warning? An #ifdef around the function? #ifdef _MSC_VER void ProcessOps::sendToExternalApp(QString sAppName, QString sImagePath, qreal qrLeft, qreal qrTop, qreal qrWidth, qreal qrHeight) #else void ProcessOps::sendToExternalApp(QString sAppName, QString