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
2 answers

How to use clang with mingw-w64 headers on windows

I have clang 3.9 from http://llvm.org/releases/3.9.0/LLVM-3.9.0-win32.exe clang version 3.9.0 (branches/release_39) Target: i686-pc-windows-msvc Thread model: posix InstalledDir: C:\Program Files\LLVM\bin And gcc 6.2.0 (Mingw-w64) gcc…
Konrad
  • 6,385
  • 12
  • 53
  • 96
22
votes
3 answers

How to link to shared lib from shared lib with relative path?

I'm working on a Firefox plugin that uses external libraries to render 3D graphics on the browser. The problem is that I want the plugin to use external libraries packed with it without changing the LD_LIBRARY_PATH variable. The libraries are…
leosamu
  • 221
  • 1
  • 2
  • 3
22
votes
2 answers

do I put [[maybe unused]] on function declarations or definitions?

C++17 introduces the attribute [[maybe_unused]]. I assume this a standardized version of GCC and Clang's: __attribute__((unused)). For unused functions that I don't want to see a warning from, should I be specifying the attribute on function…
Trevor Hickey
  • 36,288
  • 32
  • 162
  • 271
22
votes
3 answers

How to make GCC generate bswap instruction for big endian store without builtins?

Update: This was fixed in GCC 8.1. I'm working on a function that stores a 64-bit value into memory in big endian format. I was hoping that I could write portable C99 code that works on both little and big endian platforms and have modern x86…
nwellnhof
  • 32,319
  • 7
  • 89
  • 113
22
votes
2 answers

Is there a way to determine that a .a or .so library has been compiled as position indepenent code?

I am getting a linking error when compiling the numpy library against lapack indicating I need to compile lapack with -fPIC. I thought I had done just that. Is there a way to determine that the produced lapack library is position independent?
Setjmp
  • 27,279
  • 27
  • 74
  • 92
22
votes
4 answers

How to hint to GCC that a line should be unreachable at compile time?

It's common for compilers to provide a switch to warn when code is unreachable. I've also seen macros for some libraries, that provide assertions for unreachable code. Is there a hint, such as through a pragma, or builtin that I can pass to GCC (or…
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
22
votes
2 answers

Can I reliably set a function pointer to NULL in C and C++?

In P.J. Plauger's book, The Standard C Library, he warns about assigning a function pointer to NULL. Specifically, he says this: The macro NULL serves as an almost-universal null pointer constant. You use it as the value of a data-object pointer…
rationalcoder
  • 1,587
  • 1
  • 15
  • 29
22
votes
3 answers

Is memory barrier or atomic operation required in a busy-wait loop?

Consider the following spin_lock() implementation, originally from this answer: void spin_lock(volatile bool* lock) { for (;;) { // inserts an acquire memory barrier and a compiler barrier if (!__atomic_test_and_set(lock,…
gavv
  • 4,649
  • 1
  • 23
  • 40
22
votes
3 answers

Why is a placement new much faster than a direct assignment?

I recently figured out that using a placement new is faster than doing 16 assignments: Consider the following piece of code (c++11): class Matrix { public: double data[16]; Matrix() : data{ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 } …
bricklore
  • 4,125
  • 1
  • 34
  • 62
22
votes
3 answers

Injected class name compiler discrepancy

Consider this code: struct foo{}; int main() { foo::foo a; } I would expect this to be well-formed, declaring a variable of type foo by the rule in [class]/2 (N4140, emphasis mine): A class-name is inserted into the scope in which it is…
TartanLlama
  • 63,752
  • 13
  • 157
  • 193
22
votes
1 answer

How to remove a specific ELF section, without stripping other symbols?

I have an ELF 32-bit x86 file which contains an .eh_frame section, despite my attempts1 to remove it. I'd like to remove the .eh_frame section, without touching any symbols in other sections, including unused ones. strip does not seem to have an…
anol
  • 8,264
  • 3
  • 34
  • 78
22
votes
1 answer

What is wrong with this use of offsetof?

I'm compiling some c++ code in MinGW GCC 4.4.0, and getting warnings with the following form... warning: invalid access to non-static data member '' of NULL object warning: (perhaps the 'offsetof' macro was used incorrectly) This…
user180247
22
votes
4 answers

String literals vs array of char when initializing a pointer

Inspired by this question. We can initialize a char pointer by a string literal: char *p = "ab"; And it is perfectly fine. One could think that it is equivalent to the following: char *p = {'a', 'b', '\0'}; But apparently it is not the case. And…
Eugene Sh.
  • 17,802
  • 8
  • 40
  • 61
22
votes
1 answer

Program with "noexcept" constructor accepted by gcc, rejected by clang

The code: struct T { T() {} }; struct S { T t; S() noexcept = default; }; int main() { // S s; } g++ 4.9.2 accepts this with no errors or warnings, however clang 3.6 and 3.7 report for line 7: error: exception specification of…
M.M
  • 138,810
  • 21
  • 208
  • 365
22
votes
1 answer

Building with more than one version of a compiler

How can I configure travis-ci such that my project builds with more than one version of a compiler? Say, I want to build it with gcc-4.8, gcc-4.9, clang-3.4, clang-3.5 and clang-3.6. I know how to build on both gcc and clang, but not on more than…
bst
  • 426
  • 3
  • 10