C标准在哪里定义else if语句?

问题描述

我只是对C中的50语句感到好奇,所以我查看了C99标准,却一无所获。然后我看了一下语法,但又没有看else if

else if

在C中如何声明selection_statement : IF '(' expression ')' statement | IF '(' expression ')' statement ELSE statement | SWITCH '(' expression ')' statement ; 。通过阅读该标准,我怎么能注意到它是其中的一部分?

解决方法

C 2018 6.8.4说,选择声明可能是“ let query = CKQuery(recordType: "Image",predicate: NSPredicate(format: "post = %@",CKRecord.Reference(recordID: CKRecord.ID(recordName: yourPostRecordName),action: .deleteSelf))) let operation = CKQueryOperation(query: query) var images = [CKRecord]() operation.recordFetchedBlock = { record in //Load up all the images images.append(record) } operation.queryCompletionBlock = { cursor,error in //All the image records have been downloaded,or there was an error } yourContainerDatabase.add(operation) 表达式 if ( 声明 { {1}} 声明”。 C 2018 6.8表示后一个 statement 可能是“ selection-statement ”,因此它可能是)else语句,结果在包含if的语句中。

,

通过声明以下语法,在{6.8.4 / 1,C18中,else if语句正式定义为if语句的副产品:

语法

1个选择语句:

if ( expression ) statement

if ( expression ) statement else statement

资料来源:C18,第6.8.4 / 1/1

后一种形式的最后一个“ 声明”描述了if之后可以跟随另一个else语句。


除此之外,您可以在G.5.1 / 8的代码示例中的规范附录G中找到一个在C标准中使用的示例,当然是非规范的:

if (isnan(x) && isnan(y)) { ... }
else if ((isinf(a) ||isinf(b)) && isfinite(c) && isfinite(d)) { ... }
else if ((logbw == INFINITY) && isfinite(a) && isfinite(b)) { ... } 

这是唯一出现else if语句的地方,就像在C18标准中一样。

所以关于:

通过阅读标准,我怎么能注意到它是其中的一部分?

尽管示例是非规范的,但至少是示例的一部分。