gcc-warning

Strange GCC warning on storage class and type

前提是你 提交于 2019-12-02 07:56:41
I have a header file that looks like header.h int TOS; This file is being included by just one code file code.c #include "header.h" TOS=0; When compiling code.c GCC issues a warning code.c:3:1: warning: data definition has no type or storage class [enabled by default] code.c:3:1: warning: type defaults to ‘int’ in declaration of ‘TOS’ [enabled by default] I fail to understand the cause of this warning. Isn't it equivalent to declaring and defining TOS in code.c? i.e. code.c int TOS; TOS=0; It is because you define TOS in the global scope, which need you to define the type of TOS (it is an

“warning: 'struct matrix' declared inside parameter list [enabled by default]” and error: conflicting types for 'scanToken'

左心房为你撑大大i 提交于 2019-12-02 07:09:23
问题 I've been pouring over this issue trying to figure out what is causing these errors, but so far I've come up with nothing. I have this function: struct token scanToken(struct matrix refTable){ struct token send; int counter = 0; int currState = refTable.start; while (1) { printf("%d ", currState); char c = getchar(); send.buffer[counter] = c; int class = classifyChar(c); char result = refTable.grid[class][currState].action; currState = refTable.grid[class][currState].nextState; if (currState

Floating-point exceptions are signalling in new gfortran version

泄露秘密 提交于 2019-12-02 04:49:49
I am currently working to debug a subroutine of some software that my boss has written back in the 90s. There seems to be a floating-point exception that occurs in a do loop of a particular subroutine: 16 irad=1,incmax rr1=rr2 rr2=rr2+rdiv if(rr1.gt.rlimit) goto 16 if(pts(irad).gt.0.0) then discrm=(rmsden(mt,irad)/pts(irad)) 1 -((average(mt,irad)**2)/(pts(irad)**2)) else discrm=0.0 endif if(discrm.ge.0.0) then rmsden(mt,irad)=sqrt(discrm) else rmsden(mt,irad)=0.0 endif average(mt,irad)=average(mt,irad)/pts(irad) average(mt,irad)=(average(mt,irad)*100.0)/bigmost(mt) rmsden(mt,irad)=(rmsden(mt

“warning: 'struct matrix' declared inside parameter list [enabled by default]” and error: conflicting types for 'scanToken'

只谈情不闲聊 提交于 2019-12-02 02:20:04
I've been pouring over this issue trying to figure out what is causing these errors, but so far I've come up with nothing. I have this function: struct token scanToken(struct matrix refTable){ struct token send; int counter = 0; int currState = refTable.start; while (1) { printf("%d ", currState); char c = getchar(); send.buffer[counter] = c; int class = classifyChar(c); char result = refTable.grid[class][currState].action; currState = refTable.grid[class][currState].nextState; if (currState = 99){ findEnd(); send.recrej = 'd'; return send; } else if (currState = refTable.accept){ if (c == EOF

implicit declaration of function ‘strtok_r’ [-Wimplicit-function-declaration] inspite including <string.h>

穿精又带淫゛_ 提交于 2019-12-01 17:59:40
I have the following code to tokenize a string containing lines separated by \n and each line has integers separated by a \t : void string_to_int_array(char file_contents[BUFFER_SIZE << 5], int array[200][51]) { char *saveptr1, *saveptr2; char *str1, *str2; char delimiter1[2] = "\n"; char delimiter2[2] = " "; char line[200]; char integer[200]; int j; for(j = 1, str1 = file_contents; ; j++, str1 = NULL) { line = strtok_r(str1, delimiter1, &saveptr1); if (line == NULL) { break; } for (str2 = line; ; str2 = NULL) { integer = strtok_r(str2, delimiter2, &saveptr2); if (integer == NULL) { break; } }

Suppress warning: the use of `mktemp' is dangerous

会有一股神秘感。 提交于 2019-12-01 16:59:05
How can I suppress following warning from gcc linker: warning: the use of 'mktemp' is dangerous, better use 'mkstemp' I do know that it's better to use mkstemp() but for some reason I have to use mktemp() function. I guess you need the path because you pass it to a library that only accepts path names as argument and not file descriptors or FILE pointers. If so you can create a temp dir with mkdtemp and place your file there, the actual name is then unimportant because the path is already unique because of the directory. If you have to use mktemp then there is not anything you can do to

C++: warning: '…' declared with greater visibility than the type of its field '…::<anonymous>'

谁说我不能喝 提交于 2019-12-01 16:50:48
I'm getting these two warnings (with GCC 4.2 on MacOSX): /Users/az/Programmierung/openlierox/build/Xcode/../../src/main.cpp:154:0 /Users/az/Programmierung/openlierox/build/Xcode/../../src/main.cpp:154: warning: 'startMainLockDetector()::MainLockDetector' declared with greater visibility than the type of its field 'startMainLockDetector()::MainLockDetector::<anonymous>' /Users/az/Programmierung/openlierox/build/Xcode/../../src/main.cpp:154:0 /Users/az/Programmierung/openlierox/build/Xcode/../../src/main.cpp:154: warning: 'startMainLockDetector()::MainLockDetector' declared with greater

Why does -Wcast-align not warn about cast from char* to int* on x86?

时光怂恿深爱的人放手 提交于 2019-12-01 16:28:19
I understand that gcc has an option -Wcast-align which warns whenever a pointer is cast such that the required alignment of the target is increased. Here's my program: char data[10]; int ptr = *((int *)data); On my machine, the alignment requirement of data is 1 whereas it's 8 for ptr. Why don't I get a warning? Could it be because I'm compiling it for x86? The warning will never be emitted when compiling for Linux i386 or x86-64, when using the standard ABIs for these systems. Let me explain you why that is so. First, let's see what gcc's documentation has to say about -Wcast-align : Warn

A variable not detected as not used

南笙酒味 提交于 2019-12-01 16:19:35
问题 I am using g++ 4.3.0 to compile this example : #include <vector> int main() { std::vector< int > a; int b; } If I compile the example with maximum warning level, I get a warning that the variable b is not used : [vladimir@juniper data_create]$ g++ m.cpp -Wall -Wextra -ansi -pedantic m.cpp: In function ‘int main()’: m.cpp:7: warning: unused variable ‘b’ [vladimir@juniper data_create]$ The question is : why the variable a is not reported as not used? What parameters do I have to pass to get the

Suppress warning: the use of `mktemp' is dangerous

对着背影说爱祢 提交于 2019-12-01 15:23:34
问题 How can I suppress following warning from gcc linker: warning: the use of 'mktemp' is dangerous, better use 'mkstemp' I do know that it's better to use mkstemp() but for some reason I have to use mktemp() function. 回答1: I guess you need the path because you pass it to a library that only accepts path names as argument and not file descriptors or FILE pointers. If so you can create a temp dir with mkdtemp and place your file there, the actual name is then unimportant because the path is