CPP Info Memo (Part 1)
CPP Info Memo part 2

CPP Info Memo part1(2)

tubo posted @ 2014年9月04日 17:32 in 未分类 , 467 阅读

Table of Contents

1 Overview


1.1 Initial Processing


1.2 Tokenization


1.2.1 Preprocessor is greedy

It always makes each token, starting from the left, as big as possible before moving on to the next token. For instance,


is interpreted as

a ++ ++ + b

, not as

a ++ + ++ b

, even though the latter tokenization could be part of a valid C program and the former could not.


1.2.2 Token Boundary

一旦文件被分解成符号,符号的边界也就固定不变了, 除非通过 "##" 来将两个符号连接在一起。


#define foo() bar



预编译时,将会得到的 Tokens 为: bar baz, 而不是 barbaz 。


1.2.3 Tokens 的分类

预处理输出的 Tokens 可以分为五类:标识符,数字、字符串、符号、以及其他。

  • 标识符 (Indentifiers)

    定义与 C 的标识符相同: any sequence of letters, digits, or underscores, which begins with a letter or underscore.

    对于预编译来讲, C 语言的关键词 (keyword) 和普通的 Token 没有什么区别,除 了关键词 defined 之外。

  • 数字 (Preprocessing number)



    其中,指数包括: e+, e-, E+, P+ 等等。


登录 *

loading captcha image...
or Ctrl+Enter