有人可以确切地解释一下以下定义在C标准中关于指令的含义吗 [英] Can someone explain me exactly what the below definition means in the C standard about directives

查看:119
本文介绍了有人可以确切地解释一下以下定义在C标准中关于指令的含义吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真正需要知道的是在指令开始之前允许使用哪些字符,因为我们都知道在开始之前可以有换行空白字符指令(在#之前)的内容,现在我阅读了有关此内容的C标准,并找到了解释此内容的以下定义:

预处理指令由满足以下约束的一系列预处理令牌组成:该序列中的第一个令牌是#预处理令牌,(在翻译阶段4的开始)是源文件中的第一个字符( (可选)在不包含换行符的空格之后)或紧随包含至少一个换行符的空格之后. "C标准-请在此处阅读定义"

现在我真正需要知道的是: 他们是什么意思

(可选地在不包含新行"字符的空白之后)或紧随包含至少一个新行"的空白之后的字符.字符

the

不包含换行符

至少包含一个换行符

在上面的定义中我不理解,我需要知道它的确切含义,并且我需要知道

可以出现换行符的地方是在#标记之前还是在#令牌之后,C标准尚未说明换行符可以出现的地方(它仅声明不包含换行符"字符"和包含至少一个换行符")(尚未说明在这种情况下#令牌之前还是#令牌之后在哪里可以出现换行符)即使已经说明了在上述情况下空白字符可以出现在#标记之前)

解决方案

这基本上意味着:#在行的开头,或者给定行上#之前只有空格./p>

此部分:

源文件中的第一个字符(可选地,在不包含换行符的空白之后)

如果#在文件的第一行,则允许在#之前的空格,而在此部分:

或在包含至少一个换行符的空白之后.

在任何后续行中都允许在#之前的空格.

例如:

  #include <stdio.h>   // spaces before the first line
  #include <stdlib.h>  // spaces before another line, i.e, spaces and newline before a token
int x;   #include <string.h> // not allowed, other tokens preceed on same line

What i exactly need to know is what characters are allowed before the start of a directive as we all know we can have new line characters and whitespace characters before the start of a directive before ( # ) now i read the C standard about this and found out the following definition explaining this:

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. "C standard - read here the definition"

now what i exactly need to know is: what do they mean by

(optionally after whitespace containing no "new-line" characters) or that follows whitespace containing at least one "new-line" character

the

containing no new-line characters

and

containing at least one new-line character

is what i don't understand in the above definition i need to know what that exactly means and i need to know

where new-line characters can occur is it before # token or after # token the C standard haven't stated where new-line characters can occur (it only states "containing no new-line characters" and "containing atleast one new-line character") (it haven't stated whether where new-line characters can occur in this case before # token or after # token) even though it have stated where whitespace characters can occur(before # token) in the above situation

解决方案

What this all basically means is that either # is at the start of a line or there is only whitespace before # on a given line.

This part:

either the first character in the source file (optionally after white space containing no new-line characters)

Allows for whitespace before # if it's on the first line of the file, while this part:

or that follows white space containing at least one new-line character.

Allows for whitespace before # on any subsequent line.

For example:

  #include <stdio.h>   // spaces before the first line
  #include <stdlib.h>  // spaces before another line, i.e, spaces and newline before a token
int x;   #include <string.h> // not allowed, other tokens preceed on same line

这篇关于有人可以确切地解释一下以下定义在C标准中关于指令的含义吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆