Category : gcc

I’m getting a warning ([-Wmaybe-uninitialized]) on some code that I don’t think should be throwing a warning. Compiling with cmake using GCC. Basically it’s saying that a variable may not be initialized, but I think it’s guaranteed to be initialized. Here’s an example: #include<iostream> enum class ByteOrder { little_endian, big_endian }; class someClass { someClass(ByteOrder ..

Read more

I’ve written a template function whose template arguments are being correctly deduced by GCC/Clang but are ambiguous to MSVC. Here is a compiler explorer link: https://godbolt.org/z/8b376EYYr The template is declared as: template <typename Int = int, template <typename…> typename Cont = std::vector> Cont<Int> input_to_int(Cont<std::string> input); and it is used in main(): std::vector<int> int_vec = input_to_int(str_vec); ..

Read more

this is my easy code to learn vitual class,this code can be complied by clion 。 class BaseA{ public: BaseA(){}; ~BaseA(){}; int a; virtual void fuc()=0; }; class DrivedA:public BaseA{ public: DrivedA(){}; ~DrivedA(){}; int b; void fuc() override{ b=2; }; }; int main() { DrivedA drivedA; drivedA.fuc(); return 0; } this is makeLists: cmake_minimum_required(VERSION 3.21) ..

Read more

I have vs code on windows 11. I followed instruction of https://www.javatpoint.com/how-to-run-a-c-program-in-visual-studio-code up to "5. Move the mouse over the C PROGRAM folder; it shows a + Click on the button and write the file name as JavaTpoint.c, as shown below.". Every steps before that was OK. However, after "Run Code", I got "’gcc’ is ..

Read more

I wrote a simple program to load an excutable using dlopen(): #include <stdio.h> #include <dlfcn.h> int main(int argc, char* argv[]) { if (dlopen(argv[0], RTLD_NOW)) { printf("dlopen() successn"); } else { printf("dlopen() failed: %sn", dlerror()); } return 0; } Compiling with clang++-8 I get: /usr/bin/clang++-8 main.cpp -ldl -o a.out ./a.out dlopen() failed: ./a.out: cannot dynamically load ..

Read more

I was reading the GCC documentation on C and C++ function attributes. In the description of the error and warning attributes, the documentation casually mentions the following "trick": error ("message") warning ("message") If the error or warning attribute is used on a function declaration and a call to such a function is not eliminated through ..

Read more