N
nszabolcs
According to
http://c-faq.com/decl/decldef.html
global variable declaration should have 'extern' storage class
specifier, but multiple definition with at most one initialisation is
a common extension.
So is this style acceptable? (see example below)
Is there any caveats against it (beside the 'common extension'
comment)
example code:
// common.h:
int i;
void print();
void inc();
// io.c:
#include <stdio.h>
#include "common.h"
void print() {
printf("%d\n", i);
}
// calc.c:
#include "common.h"
void inc() {
i++;
}
// main.c:
#include "common.h"
int main() {
i = 0;
print();
inc();
print();
return 0;
}
thanks for your advice
nsz
http://c-faq.com/decl/decldef.html
global variable declaration should have 'extern' storage class
specifier, but multiple definition with at most one initialisation is
a common extension.
So is this style acceptable? (see example below)
Is there any caveats against it (beside the 'common extension'
comment)
example code:
// common.h:
int i;
void print();
void inc();
// io.c:
#include <stdio.h>
#include "common.h"
void print() {
printf("%d\n", i);
}
// calc.c:
#include "common.h"
void inc() {
i++;
}
// main.c:
#include "common.h"
int main() {
i = 0;
print();
inc();
print();
return 0;
}
thanks for your advice
nsz