forked from CaptGreg/SenecaOOP345-attic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
c-namespace.c
41 lines (33 loc) · 1.18 KB
/
c-namespace.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
// a student said C99 has namespace support
// Let's see:
// This program works as expected in C++:
// g++ c-namespace.c -o c-namespace && ./c-namespace
// namespace 'n::n' value = 3
// now try it in C99:
/*
gcc -std=c99 c-namespace.c -c c-namespace
c-namespace.c:32:1: error: unknown type name ‘namespace’
namespace n {
^
c-namespace.c:32:13: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
namespace n {
^
c-namespace.c: In function ‘main’:
c-namespace.c:38:43: error: ‘n’ undeclared (first use in this function)
printf("namespace 'n::n' value = %d\n", n::n);
^
c-namespace.c:38:43: note: each undeclared identifier is reported only once for each function it appears in
c-namespace.c:38:44: error: expected ‘)’ before ‘:’ token
printf("namespace 'n::n' value = %d\n", n::n);
^
*/
// no namespaces in C99
#include <stdio.h>
namespace n {
int n = 3;
}
int main(int argc, char*argv[])
{
printf("namespace 'n::n' value = %d\n", n::n);
return 0;
}