-
Notifications
You must be signed in to change notification settings - Fork 0
/
054_Whitespace.c
57 lines (49 loc) · 1.27 KB
/
054_Whitespace.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* pg: 53 ECP */
#include <stdio.h>
int main(int argc, char *argv[])
{
char a[] = "this is very long string \
split into two lines";
int x = 6, y = 2, z;
printf("String is: %s\n", a);
z = y++;
printf("x is: %d\n", x); /* x is 6 */
printf("y is: %d\n", y); /* y is 3 */
printf("z is: %d\n", z); /* z is 2 */
/* Maximal Munch
* Read this as
* z = (y++) + x;
*/
z = y+++x;
printf("x is: %d\n", x); /* x is 6 */
printf("y is: %d\n", y); /* y is 4 */
printf("z is: %d\n", z); /* z is 9 */
/* Maximal munch should have read this
* as z = (y++) + (x); like above
* resulting in x = 6; y = 6 and z = 10.
* BUT white space matters!
* The gcc reads it as z = y + (++x);
* resulting in x = 7, y = 4 and x = 11
*/
z = y + ++x;
printf("x is: %d\n", x); /* x is 7 */
printf("y is: %d\n", y); /* y is 4 */
printf("z is: %d\n", z); /* z is 11 */
z = y++ + ++x;
printf("x is: %d\n", x); /* x is 8 */
printf("y is: %d\n", y); /* y is 5 */
printf("z is: %d\n", z); /* z is 12 */
#if 0
/* maximal Munch
* error: lvalue required as increment operand
* Maximal Munch
* Read this as
* z = (y++) (++) + x;
*/
z = y+++++x;
printf("x is: %d\n", x); /* x is 8 */
printf("y is: %d\n", y); /* y is 5 */
printf("z is: %d\n", z); /* z is 12 */
#endif
return 0;
}