在第一列需要 # 的编译器?

Compilers that required # on the first column?

是否有广泛使用的 ANSI C 之前的编译器 要求 # 位于第一列?

† I would accept any compiler on this list. If I can find mention of it in the comp.lang.c Usenet newsgroup in a post dated before 1995, I would accept it.

K&R C 没有指定 # 之前是否允许空格。摘自原文 The C Programming Language,附录 A 中 "C Reference Manual" 的§12¶1:

The C compiler contains a preprocessor capable of macro substitution, conditional compilation, and inclusion of named files. Lines beginning with # communicate with this preprocessor.

因此,未指定是否允许在 # 之前使用空格。这意味着如果指令没有从第一列开始,ANSI 之前的编译器可能无法编译程序。

在 ISO C(以及之前的 ANSI C)中,C 预处理指令被明确允许使用空格作为前缀。在 ANSI C (C-89) 中:

A preprocessing directive consists of a sequence of preprocessing tokens that begins with a # preprocessing token that is either the first character in the source file (optionally after white space containing no new-line characters) or that follows white space containing at least one new-line character, and is ended by the next new-line character.

ISO C.2011 有类似的语言,但进一步阐明:

A preprocessing directive consists of a sequence of preprocessing tokens that satisfies the following constraints: The first token in the sequence is a # preprocessing token that (at the start of translation phase 4) is either the first character in the source file (optionally after white space containing no new-line characters) or that follows white space containing at least one new-line character. The last token in the sequence is the first newline character that follows the first token in the sequence.165) A new-line character ends the preprocessing directive even if it occurs within what would otherwise be an invocation of a function-like macro.
165) Thus, preprocessing directives are commonly called ‘‘lines’’. These ‘‘lines’’ have no other syntactic significance, as all white space is equivalent except in certain situations during preprocessing (see the # character string literal creation operator in 6.10.3.2, for example).

简答:是。

我记得写过这样的东西

#if foo
    /* ... */
#else
#if bar
    /* ... */
#else
 #error "neither foo nor bar specified"
#endif
#endif

这样我曾经使用过的各种 pre-ANSI 编译器就不会抱怨 "unrecognized preprocessor directive '#error'"。这本来是 Ritchie 的原始 cc 用于 pdp11 或 pcc("portable C compiler",IIRC 是 80 年代左右 Vax cc 的基础)。这两个编译器——更准确地说,是与这两个编译器一起使用的预处理器——绝对要求 # 位于第一列。 (实际上,尽管这些编译器非常不同,但它们可能都使用了基本相同的预处理器的不同变体,在那些日子里它总是一个单独的程序。)