Questions tagged [gcc]

GCC is the GNU Compiler Collection. It's the de facto standard compiler for C, C++, Go, Fortran, and Ada on Linux and supports many other languages and platforms as well.

GCC is the GNU Compiler Collection, a collection of free software compilers. It is a key component of the GNU Toolchain.

GCC includes an optimizing C compiler that is the most commonly used C compiler on Linux. GCC also includes front ends for C++ (including full support for C++17), Objective-C, Fortran, Ada, and Go, as well as libraries for these languages (libstdc++, libgfortran, ...). It supports many architectures.

GCC sources are available via the Git repository. Major decisions about GCC are made by the steering committee, guided by the mission statement.

See also GCC online documentation and the home page, and release dates.

40905 questions
22
votes
1 answer

Is GCC miscompiling this code, or is it UB?

Consider this code: #include template struct DefaultMsgImpl { DefaultMsgImpl() { memset(this, 0, sizeof(T)); } }; struct Msg : DefaultMsgImpl { int num; }; int f() { Msg msg{.num = 66}; return…
John Zwinck
  • 239,568
  • 38
  • 324
  • 436
22
votes
3 answers

Cannot find -lc and -lm in g++ linux

I am using Ubuntu and gcc and g++ were working fine but today it showed: cannot find -lm cannot find -lc I searched and found it has something to do with /usr/bin/ld. Which is a symlink (I hope) to lbd.bdf. I pasted that file in the directory from…
Ashish Negi
  • 5,193
  • 8
  • 51
  • 95
22
votes
2 answers

Header alloca.h in Windows

I can't see any alloca.h equivalent in Visual C 2010. How can one perform stack allocation in Visual C on Windows? I miss the function alloca.
Cartesius00
  • 23,584
  • 43
  • 124
  • 195
22
votes
18 answers

List of common C++ Optimization Techniques

Can I have a great list of common C++ optimization practices? What I mean by optimization is that you have to modify the source code to be able to run a program faster, not changing the compiler settings.
yoitsfrancis
  • 4,278
  • 14
  • 44
  • 73
22
votes
2 answers

Why do compilers insist on using a callee-saved register here?

Consider this C code: void foo(void); long bar(long x) { foo(); return x; } When I compile it on GCC 9.3 with either -O3 or -Os, I get this: bar: push r12 mov r12, rdi call foo mov rax, r12 …
22
votes
8 answers

How to enable experimental C++11 concurrency features in MinGW?

When trying to compile the following code #include #include void foo() { std::cout << "foo\n"; } int main() { std::thread t(foo); t.join(); } I get an error: C:\Test>g++ -g -Wall -lpthread -std=c++0x main.cpp main.cpp: In…
Loom
  • 9,768
  • 22
  • 60
  • 112
22
votes
2 answers

C++ constexpr function in return statement

Why is a constexpr function no evaluated at compile time but in runtime in the return statement of main function? It tried template constexpr int fac() { return fac() * x; } template<> constexpr int fac<1>() { return 1; }…
Thomas Sablik
  • 16,127
  • 7
  • 34
  • 62
22
votes
3 answers

Installing GCC from source on Alpine

While trying to install GCC 6.4.0 on Alpine, I run into: checking for the correct version of gmp.h... yes checking for the correct version of mpfr.h... yes checking for the correct version of mpc.h... yes checking for the correct version of the…
Gabriel Fernandez
  • 580
  • 1
  • 3
  • 14
22
votes
3 answers

Intermittent, random 'file not found' errors under Windows Subsystem for Linux (WSL)

I'm getting intermitting 'fatal error: ... file not found' errors building C++ application using either gcc 4.8 or clang 3.8 under Ubuntu 16.04.2 running in Windows Subsystem for Linux (WSL), when including C++ header files, but only since…
Andrew Medlin
  • 461
  • 3
  • 11
22
votes
5 answers

Standard library containers producing a lot of copies on rvalues in GCC

I'm writing a app for both linux & windows, and noticed that the GCC build is producing a lot of useless calls to the copy constructor. Here's an example code to produce this behavior: struct A { A() { std::cout << "default" <<…
Inverse
  • 4,408
  • 2
  • 26
  • 35
22
votes
2 answers

Why does make -j perform better when it is passed a number larger than the number of cores available?

I have a quad-core processor with hyper-threading. When I use make -j8 it is faster than make -j4 (I read the number of cores in Java and then called make -j). I don't understand why make -j32 is faster than make -j8 when I have…
Damir
  • 54,277
  • 94
  • 246
  • 365
22
votes
5 answers

How do I install gcc on cygwin?

$ uname -r 2.9.0(0.318/5/3) I don't have the gcc or the g++ command on my path after I install cygwin. What packages do I need to install to get this command?
Daniel Kaplan
  • 62,768
  • 50
  • 234
  • 356
22
votes
1 answer

Is returning a 2-tuple less efficient than std::pair?

Consider this code: #include #include std::pair f1() { return std::make_pair(0x111, 0x222); } std::tuple f2() { return std::make_tuple(0x111, 0x222); } Clang 3 and 4 generate similar code for both on…
John Zwinck
  • 239,568
  • 38
  • 324
  • 436
22
votes
9 answers

Integer cube root

I'm looking for fast code for 64-bit (unsigned) cube roots. (I'm using C and compiling with gcc, but I imagine most of the work required will be language- and compiler-agnostic.) I will denote by ulong a 64-bit unisgned integer. Given an input n I…
Charles
  • 11,269
  • 13
  • 67
  • 105
22
votes
2 answers

Error message "undefined reference to template function passed as template parameter"

When I pass a template function as a template parameter of a base class, the linker complains that it cannot link the function: #include template inline int identity() {return I;} //template<> inline int identity<10>() {return…
Ferenc
  • 779
  • 1
  • 6
  • 14