gcc-warning

How to circumvent format-truncation warning in GCC?

♀尐吖头ヾ 提交于 2019-12-03 17:52:32
问题 I'm getting the following gcc format-truncation warning: test.c:8:33: warning: ‘/input’ directive output may be truncated writing 6 bytes into a region of size between 1 and 20 [-Wformat-truncation=] snprintf(dst, sizeof(dst), "%s-more", src); ^~~~~~ test.c:8:3: note: ‘snprintf’ output between 7 and 26 bytes into a destination of size 20 snprintf(dst, sizeof(dst), "%s-more", src); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ on code like this: char dst[20]; char src[20]; scanf("%s", src);

How to disable all warnings in g++ on a few lines of code

好久不见. 提交于 2019-12-03 15:53:23
How to disable all warnings on a few lines of code. Specific warnings can be disabled using GCC diagnostic feature, but is there a flag for all warnings. I tried this way but it doesn't work #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-wall" // some code #pragma GCC diagnostic pop From here: http://dbp-consulting.com/tutorials/SuppressingGCCWarnings.html For version 4.6 or later, you can save the state of the user's diagnostic flags. You can insert this around the line that causes the spurious warning: #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated

Suppress Compiler warning Function declared never referenced

落花浮王杯 提交于 2019-12-03 15:24:00
问题 So i have some code like this: void foo (int, int); void bar ( ) { //Do Stuff #if (IMPORTANT == 1) foo (1, 2); #endif } When doing a compile without "IMPORTANT" I get a compiler Warning that foo is defined and never referenced. Which got me thinking (that is the problem). So to fix this i just added the same #if (IMPORTANT == 1) around the function definition etc... to remove the warning, and then I started to wonder if there was a different way to suppress that warning on that function. I

how to disable gcc warning “cc1: warning: command line option ‘-std=c++11’ is valid for C++/ObjC++ but not for C [enabled by default]”

柔情痞子 提交于 2019-12-03 12:29:46
问题 I am new to cmake and gcc. The first assignment in my new role in the company was to clean the errors from our linux compilation I did most of it, and now the only warning I see is cc1: warning: command line option ‘-std=c++11’ is valid for C++/ObjC++ but not for C [enabled by default] I want wither to suppress the warning or to solve the issue in the cmake file. Unfortunately, I still haven't found the correct -Wno-xxx statement that fits here. Thanks! 回答1: Code issue warnings can be

How to use C++20's likely/unlikely attribute in if-else statement

我与影子孤独终老i 提交于 2019-12-03 10:27:25
This question is about C++20's [[likely]] / [[unlikely]] feature, not compiler-defined macros. This documents ( cppreference ) only gave an example on applying them to a switch-case statement. This switch-case example compiles perfectly with my compiler (g++-7.2) so I assume the compiler has implemented this feature, though it's not yet officially introduced in current C++ standards. But when I use them like this: if (condition) [[likely]] { ... } else { ... } , I got a warning: "warning: attributes at the beginning of statement are ignored [-Wattributes]". So how should I use these attributes

function declared static but never defined

早过忘川 提交于 2019-12-03 05:30:06
问题 I have a header file suppose abc.h, where i have function declaration as: static int function1(); I have included this header file in abc.c and has defined the function and used it. static int function1() { < function definition> } After compiling I am getting warning: warning: function1 declared static but never defined How can I remove warning, without removing static. Thanks. 回答1: A static function can be declared in a header file, but this would cause each source file that included the

Don't understand “assuming signed overflow” warning

隐身守侯 提交于 2019-12-03 04:38:58
I am getting: warning: assuming signed overflow does not occur when assuming that (X + c) < X is always false [-Wstrict-overflow] on this line: if ( this->m_PositionIndex[in] < this->m_EndIndex[in] ) m_PositionIndex and m_EndIndex of type itk::Index ( http://www.itk.org/Doxygen/html/classitk_1_1Index.html ), and their operator[] returns a signed long . (it is line 37 here: https://github.com/Kitware/ITK/blob/master/Modules/Core/Common/include/itkImageRegionConstIteratorWithIndex.hxx for context) Can anyone explain what would cause that warning here? I don't see the pattern (x+c) < x anywhere -

how to disable gcc warning “cc1: warning: command line option ‘-std=c++11’ is valid for C++/ObjC++ but not for C [enabled by default]”

﹥>﹥吖頭↗ 提交于 2019-12-03 02:52:54
I am new to cmake and gcc. The first assignment in my new role in the company was to clean the errors from our linux compilation I did most of it, and now the only warning I see is cc1: warning: command line option ‘-std=c++11’ is valid for C++/ObjC++ but not for C [enabled by default] I want wither to suppress the warning or to solve the issue in the cmake file. Unfortunately, I still haven't found the correct -Wno-xxx statement that fits here. Thanks! Code issue warnings can be silenced with -Wno-xxx options because sometimes you don't have control over the source code. But a warning telling

function declared static but never defined

主宰稳场 提交于 2019-12-02 18:48:15
I have a header file suppose abc.h, where i have function declaration as: static int function1(); I have included this header file in abc.c and has defined the function and used it. static int function1() { < function definition> } After compiling I am getting warning: warning: function1 declared static but never defined How can I remove warning, without removing static. Thanks. A static function can be declared in a header file, but this would cause each source file that included the header file to have its own private copy of the function, which is probably not what was intended. Are u sure

Strange GCC warning on storage class and type

我的未来我决定 提交于 2019-12-02 17:16: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;