Community
Participate
Working Groups
#include <iostream> #include <stdio.h> #include <string.h> using namespace std; int main() { double var2 = 3; char string1[] = "hello"; char string2[] = "hello2"; strncpy(string1,string2); // <-------- a compiler error var2 = string1 // <----- a compiler error } This code generate compiler error the error message for gcc is prova.cpp:17:2: warning: no newline at end of file prova.cpp: In function ‘int main()’: /usr/include/string.h:89: error: too few arguments to function ‘char* strncpy(char*, const char*, size_t)’ prova.cpp:13: error: at this point in file prova.cpp:16: error: cannot convert ‘char [6]’ to ‘double’ in assignment prova.cpp:17: error: expected `;' before ‘}’ token but on Eclipse Console the output is: **** Build of configuration Debug for project ProvaSearch **** make -k all Building file: ../prova.cpp Invoking: GCC C++ Compiler g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"prova.d" -MT"prova.d" -o"prova.o" "../prova.cpp" ../prova.cpp:17:2: warning: no newline at end of file ../prova.cpp: In function ‘int main()’: Build complete for project ProvaSearch The console output is truncated, this kind of truncation seem to occur in general if number of arguments don' t correspond with definition correcting the strncpy error with for example "strncpy(string1,string2,5);": there isn' t the truncation all error are reported correctly **** Build of configuration Debug for project ProvaSearch **** make -k all Building file: ../prova.cpp Invoking: GCC C++ Compiler g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"prova.d" -MT"prova.d" -o"prova.o" "../prova.cpp" ../prova.cpp:17:2: warning: no newline at end of file ../prova.cpp: In function ‘int main()’: ../prova.cpp:16: error: cannot convert ‘char [6]’ to ‘double’ in assignment ../prova.cpp:17: error: expected `;' before ‘}’ token make: *** [prova.o] Error 1 make: Target `all' not remade because of errors. Build complete for project ProvaSearch The problem is not limited to console infact eclipse in the first "with truncation" case sign 0 error, in the second sign correctly 3 error
*** Bug 156788 has been marked as a duplicate of this bug. ***
I think this could've been solved with bug 71511. *** This bug has been marked as a duplicate of bug 71511 ***