-
Notifications
You must be signed in to change notification settings - Fork 160
/
Copy pathglobal.c
40 lines (29 loc) · 785 Bytes
/
global.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
# global scope
What you can or can't do on global scope.
*/
#include "common.h"
/* This is a global variable: can be accessed and modified everywhere */
int global = 1;
int constGlobal = 1;
/* OK, const. Operators are magic functions. */
int global2 = 1 + 1;
/* ERROR: only var declarations with const initialization allowed. Compare to C++. */
int ret1() {
return 1;
}
/* Non-const. */
/*int global2 = global + 1;*/
/*int global2 = constGlobal + 1*/
/* Funcion call. */
/*puts("asdf");*/
/*int global3 = ret1();*/
/* ERROR Cannot create scopes or branch in global scope. */
/*{}*/
/*if(1){}*/
int main(void) {
assert(global == 1);
assert(constGlobal == 1);
assert(global2 == 2);
return EXIT_SUCCESS;
}