Can someone explain me exactly what the below definition means in the C standard about directives

霸气de小男生 提交于 2020-07-03 01:40:23

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/62629483/can-someone-explain-me-exactly-what-the-below-definition-means-in-the-c-standard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!