c陷阱与缺陷第一章笔记——Lexical Pitfalls
1.3 Greedy lexical analysis
Maximal munch strategy
The way to convert a C program to tokens is to move from left to right, taking the longest possible token each time.
a---b
means a -- - b
Nested comments
#include<stdio.h>
int main(void)
{
char *s = "this is a /*nested comments*/!";
puts(s);
int n = /*/*/2*/**/3;
printf("%d\n", n);
return 0;
}
output:
this is a /*nested comments*/!
6
So, the C compiler doesn’t allow nested comments.
Character ‘yes’
if
char c = 'yes';
then
c = 's';
见C Primer Plus 学习笔记——第三章 Data and C
Exercise 1.4 What does a+++++b mean?
It means a ++ ++ + b
However, the result of a++
is not an lvalue and hence is not acceptable as an operand of ++
.