Tag: gcc warning

GCC -Wuninitialized / -Wmaybe -ininitialized问题

我正在使用gcc-4.7 (Ubuntu/Linaro 4.7.2-11precise2) 4.7.2遇到一个非常奇怪的问题。 我没有警告就无法编译以下有效代码: 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; } 编译选项和输出: $ 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 […]

gcc警告:标量初始化器周围的大括号

我有如下定义的查找表,我正在使用GCC。 当我编译时,我收到警告 warning: braces around scalar initializer 这个警告意味着什么? 我该如何初始化这个LUT? 我在初始化这个结构时犯了错误吗? 救命!! typedef struct TECH { float velocity1, velocity2; float temp; float measure; int id; float storage[64]; }TECH; struct TECH lut_model_1[2] = {{{296.001465}, {74.216972}, {2.025908}, {1.516384}, {1}, {0.001746, 0.000256, 0.006216, 0.005249, -0.001668, -0.001377, 0.009865, 0.010454, -0.000288, -0.005853, 0.010584, 0.015440, 0.000465, -0.000602, 0.004330, 0.005700, 0.017120, 0.233015, 0.034154, […]

为什么GCC有时只在初始化之前检测到变量的使用?

我正在阅读一本书中的一些代码,当我决定在while语句之前进行更改以查看sec的未初始化值是什么while : #include #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; printf(“%d sec is %d […]

MSVC相当于__attribute __((warn_unused_result))?

我发现__attribute__ ((warn_unused_result))作为一种鼓励开发人员不要忽略函数返回的错误代码的方法非常有用,但我需要使用它来处理MSVC以及gcc和gcc兼容的编译器,如ICC。 Microsoft Visual Studio C / C ++编译器是否具有等效机制? (到目前为止,我试过通过MSDN没有任何运气。)