Tagged Questions
64
votes
3answers
20k views
How exactly does __attribute__((constructor)) work?
It seems pretty clear that it is supposed to set things up.
When exactly does it run?
Why are there two brackets?
Is __attribute__ a function? A macro? Syntax?
Does this work in C? C++?
Does the ...
56
votes
8answers
124k views
gcc makefile error: “No rule to make target …”
I'm trying to use GCC (linux) with a makefile to compile my project.
I get the following error which is can't seem to decipher in this context:
"No rule to make target vertex.cpp', needed by ...
47
votes
8answers
16k views
likely/unlikely macros in the Linux kernel
I've been digging through some parts of the Linux kernel, and found calls like this:
if (unlikely(fd < 0))
{
/* Do something */
}
or
if (likely(!err))
{
/* Do something */
}
I've ...
40
votes
8answers
10k views
Why can you return from a non-void function without returning a value without producing 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, ...
40
votes
4answers
13k views
Clang vs GCC - which produces better binaries?
I'm currently using GCC, but I discovered Clang recently and I'm pondering switching. There is one deciding factor though - quality (speed, memory footprint, reliability) of binaries it produces - if ...
35
votes
4answers
29k views
function declaration isn't a prototype
I have a library I created,
mylib.c:
#include <mylib.h>
int
testlib() {
printf("Hello world\n");
return (0);
}
mylib.h:
#include <stdio.h>
extern int testlib();
In my ...
34
votes
9answers
2k views
Is it a good idea to compile a language to C?
All over the web, I am getting the feeling that writing a C backend for a compiler is not such a good idea anymore. GHC's C backend is not being actively developed anymore (this is my unsupported ...
32
votes
7answers
27k views
Update GCC on OSX
So I am a new programmer and I just installed XCode on my Macbook to get the GCC. I think Xcode is the only way for getting GCC on OSX. Now when I run my Hello World application, in C++, g++ comes up ...
32
votes
8answers
36k views
Is there a way to install gcc in OSX without installing Xcode?
I've googled the hell out of it, and it seems like there is no way to install gcc on OS X without installing Xcode (which takes at leats 1.5GB of space). All I need is gcc and none of the other junk ...
32
votes
4answers
942 views
Can a compiler automatically detect pure functions without the type information about purity?
So I'm arguing with my friend who claims that a compiler like GCC can detect a pure function automatically without any type information. I doubt that.
Languages like D or Haskell have purity in their ...
31
votes
12answers
16k views
Why does GCC-Windows depend on cygwin?
I'm not a C++ developer, but I've always been interested in compilers, and I'm interested in tinkering with some of the GCC stuff (particularly LLVM).
On Windows, GCC requires a POSIX-emulation layer ...
28
votes
2answers
2k views
Template instantiation details of GCC and MS compilers
Could anyone provide a comparison or specific details of how is template instantiation
handled at compile and/or link time in GCC and MS compilers? Is this process different
in the context of ...
27
votes
9answers
7k views
Invoking GCC as “cc” versus “gcc”
I am aware that on most GNU/Linux systems, GCC can be invoked by the name "cc" from the command line (as opposed to "gcc"). Is there any difference in GCC's behavior when it is invoked one way versus ...
24
votes
2answers
4k views
Is gcc C compiler written in C itself?
Is gcc C compiler written in C itself ? Or is it written in Assembly ? If the compiler is written in C, then what is the compiler used to compile the compiler code ?
18
votes
7answers
2k views
how to raise warning if return value is disregarded - gcc or static code check?
I'd like to see all the places in my code (C++) which disregard return value of a function. How can I do it - with gcc or static code analysis tool?
Bad code example:
int f(int z) {
return z + ...