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 3:24

>>8
No, the linker will allocate the storage only once and make all variables refer to it.

That's not how C works.

Name: Anonymous 2011-12-13 5:36

>>7

yeap.

Doing

globals.h

int i = 0;


f1.c

#include "globals.h"

int f1() {
  ...
}


f2.c

#include "globals.h"

int f2() {
  ...
}


Is equivalent to:

f1.c

int i = 0;

int f1() {
  ...
}


f2.c

int i = 0;

int f2() {
  ...
}



So there will be an i defined in f1.c and an i defined in f2.c. If you were to compile both f1.c and f2.c, you'd get a linker error, saying that there are two symbols with the same name between f1.o and f2.o.

Name: Anonymous 2011-12-13 6:15

>>15
extern int i;

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