Category : g++

If the compiler has some command-line flags and the code has some pragmas that are incompatible with those flags, which one will be used? To be clearer: I am compiling with g++ -g -O2 -std=gnu++17 -static {files} – GCC version g++ (Ubuntu 9.3.0-10ubuntu2) 9.3.0. If I write in my code #pragma GCC optimize("Ofast"), will the ..

Read more

I try to compile JDK source code on Ubuntu 20.04 however,the configure script of JDK failed with some errors: // conftest.cpp #include <ft2build.h> #include FT_FREETYPE_H int main() { FT_Library library; FT_Error error = FT_Init_FreeType(&library); if (error) { printf("Error occurred during init.n"); } else { printf("Initialised OK!n"); } return 0; } In Terminal, this can link ..

Read more

AFAIK, "designated initialization" is a C++20 feature(ref: https://en.cppreference.com/w/cpp/language/aggregate_initialization). However, the following code, // main.cc #include <iostream> struct Person { const char *name; int age; }; int main(int argc, char *argv[]) { Person person = { .name = "Bob", .age = 24, }; std::cout << person.name << "n" << person.age << "n"; return 0; } compiles ..

Read more

I am learning C++ and using VS CODE as my editor. The problem is that my compiler says that it can’t find the header files created by me. Starting build… C:MinGWbing++.exe -g C:UsersberkbDesktopcodesaccppmainstest.cpp -o C:UsersberkbDesktopcodesaccppmainstest.exe C:UsersberkbDesktopcodesaccppmainstest.cpp:7:10: fatal error: split.h: No such file or directory 7 | #include "split.h" | ^~~~~~~~~ compilation terminated. Build finished with ..

Read more

I have the following code snippet: #include <cstddef> #include <vector> template <typename T, size_t CAPACITY> class Container { std::vector<T> storage; public: static constexpr auto capacity() { return CAPACITY; } ///Some methods where CAPACITY is used }; class Dummy { Container<int, 5> container; void dummy() { static_assert(container.capacity(), "Does not compile"); ///<===Fails with Clang static_assert(decltype(container)::capacity(), "Compiles"); } ..

Read more