Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

static anus

Name: Anonymous 2011-12-11 22:42

are variables declared in C headers static even if you don't put static with them?

Name: Anonymous 2011-12-13 9:09

>>14-16
There's one thing that always amazes me in idiots and it's their impenetrable belief that they are right. I fully understand that in fact it is the reason they are idiots, and everything else, like being ignorant and stupid, are the consequences.

But still I see someone like that guy, who not only corrected me, but also WROTE THE WHOLE FUCKING TEST CODE, but did not spend five more seconds to see if it indeed produces a linker error, and I just sit here in profound amazement. How the fuck is that possible?


#!/bin/sh

cat >test1.c <<*EOF*
#include <stdio.h>
int x;
int f(void);
int main(int argc, const char * argv[])
{
    printf("%d %d\n", x, f());
}
*EOF*

cat >test2.c <<*EOF*
int x = 42;
*EOF*

cat >test3.c <<*EOF*
int x;
int f(void) { return x + 1; }
*EOF*

gcc -c test1.c
gcc -c test2.c
gcc -c test3.c
gcc -o test test1.o test2.o test3.o
./test


HOLY SHIT NO FUCKING ERRORS AND IT WORKS CORRECTLY WOW!

Name: >>17 2011-12-13 9:32

To see that it's not a bug in GCC, you have to download the C99 standard: http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf, then head to the section 6.2.2 "Linkages of identifiers" and read it. Paragraph 5 says it as clear as possible:

If the declaration of an identifier for a function has no storage-class specifier, its linkage is determined exactly as if it were declared with the storage-class specifier extern. If the declaration of an identifier for an object has file scope and no storage-class specifier, its linkage is external.
The `extern` specifier is fucking implied, if there's no other fucking storage specifier. Except for one little detail: if all declarations use actual `extern`, you do get a linker error. Also, you get a linker error if you include initializer more than once (section 6.9.2). Hence, the standard way of declaring global variables: use `extern` in the header, include the header in the corresponding code file, define and initialize the variable there. This way you are safe from most silly errors where you, say, changed the definition but failed to recompile some object files.

Name: >>18 2011-12-13 9:39

And holy shit, I'm still amazed by >>15, I mean, what the actual fuck? I'd have understood if he just wrote some unsubstantiated bullshit. But he spent some time writing up actual files, several minutes probably! And then BAM, he ain't got no five seconds more to compile them. What. The. Fuck.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List