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.
6,958
questions
358
votes
15
answers
576k
views
Removing trailing newline character from fgets() input
I am trying to get some data from the user and send it to another function in gcc. The code is something like this.
printf("Enter your Name: ");
if (!(fgets(Name, sizeof Name, stdin) != NULL)) {
...
116
votes
3
answers
34k
views
How to remove "noise" from GCC/clang assembly output?
I want to inspect the assembly output of applying boost::variant in my code in order to see which intermediate calls are optimized away.
When I compile the following example (with GCC 5.3 using g++ -...
597
votes
11
answers
260k
views
Why does the order in which libraries are linked sometimes cause errors in GCC?
Why does the order in which libraries are linked sometimes cause errors in GCC?
50
votes
1
answer
20k
views
32-bit absolute addresses no longer allowed in x86-64 Linux?
64 bit Linux uses the small memory model by default, which puts all code and static data below the 2GB address limit. This makes sure that you can use 32-bit absolute addresses. Older versions of gcc ...
245
votes
12
answers
350k
views
Multiple glibc libraries on a single host
My linux (SLES-8) server currently has glibc-2.2.5-235, but I have a program which won't work on this version and requires glibc-2.3.3.
Is it possible to have multiple glibcs installed on the same ...
107
votes
3
answers
40k
views
Is gcc 4.8 or earlier buggy about regular expressions?
I am trying to use std::regex in a C++11 piece of code, but it appears that the support is a bit buggy. An example:
#include <regex>
#include <iostream>
int main (int argc, const char * ...
276
votes
5
answers
39k
views
Why does GCC use multiplication by a strange number in implementing integer division?
I've been reading about div and mul assembly operations, and I decided to see them in action by writing a simple program in C:
File division.c
#include <stdlib.h>
#include <stdio.h>
int ...
189
votes
11
answers
93k
views
Why does flowing off the end of a non-void function without returning a value not produce a compiler error?
Ever since I realized many years ago, that this doesn't produce an error by default (in GCC at least), I've always wondered why?
I understand that you can issue compiler flags to produce a warning, ...
1884
votes
37
answers
1.8m
views
fatal error: Python.h: No such file or directory
I am trying to build a shared library using a C extension file but first I have to generate the output file using the command below:
gcc -Wall utilsmodule.c -o Utilc
After executing the command, I ...
26
votes
1
answer
14k
views
How to load address of function or label into register
I am trying to load the address of 'main' into a register (R10) in the GNU Assembler. I am unable to. Here I what I have and the error message I receive.
main:
lea main, %r10
I also tried the ...
55
votes
16
answers
75k
views
Why is scanf() causing infinite loop in this code?
I've a small C-program which just reads numbers from stdin, one at each loop cycle. If the user inputs some NaN, an error should be printed to the console and the input prompt should return again. On ...
36
votes
3
answers
9k
views
Why doesn't GCC use partial registers?
Disassembling write(1,"hi",3) on linux, built with gcc -s -nostdlib -nostartfiles -O3 results in:
ba03000000 mov edx, 3 ; thanks for the correction jester!
bf01000000 mov edi, 1
31c0 ...
557
votes
21
answers
898k
views
Undefined reference to vtable
When building my C++ program, I'm getting the error message
undefined reference to 'vtable...
What is the cause of this problem? How do I fix it?
It so happens that I'm getting the error for the ...
18
votes
1
answer
4k
views
How can I indicate that the memory *pointed* to by an inline ASM argument may be used?
Consider the following small function:
void foo(int* iptr) {
iptr[10] = 1;
__asm__ volatile ("nop"::"r"(iptr):);
iptr[10] = 2;
}
Using gcc, this compiles to:
foo:
nop
...
697
votes
31
answers
510k
views
How to automatically generate a stacktrace when my program crashes
I am working on Linux with the GCC compiler. When my C++ program crashes I would like it to automatically generate a stacktrace.
My program is being run by many different users and it also runs on ...