非常教程

C参考手册

C 语法

#pragma directive

实现定义的行为由#pragma指令控制。

句法

#pragma pragma_params

(1)

_Pragma ( string-literal )

(2)

(since C99)

1)以实现定义的方式运行(除非 pragma_params 是下面显示的标准编译指示之一。

2)删除字串文本编码前缀(如果有的话),外报价,和前/后空白,替换每个\""每个\\\,然后标记化的结果(如在翻译阶段3),然后使用该结果作为如果输入到#pragma(1)中。

说明

编译指示控制编译器的特定于实现的行为,例如禁用编译器警告或更改对齐要求。任何未被识别的杂注将被忽略。

标准杂注

语言标准定义了以下三个编译指示:

#pragma STDC FENV_ACCESS arg

(1)

#pragma STDC FP_CONTRACT arg

(2)

#pragma STDC CX_LIMITED_RANGE arg

(3)

其中 arg 是任一ONOFFDEFAULT

1)如果设置为ON,则通知编译器该程序将访问或修改浮点环境,这意味着禁止可能破坏标志测试和模式更改的优化(例如全局公共子表达式消除,代码运动和常量折叠) 。默认值通常是实现定义的OFF

2)允许浮点表达式的收缩,即忽略舍入错误和浮点异常的优化,如果表达式完全按照写法进行计算,则可以观察到这些异常。例如,允许(x*y) + z使用单个融合的乘加 CPU 指令来实现。默认值通常是实现定义的ON

3)通知编译器,复数乘法,除法和绝对值可以用简化的数学公式(x + iy)×(u + iv)=(xu-yv)+ i(yu + xv),(x + iy )/(u + iv)=(xu + yv)+ i(yu-xv)/(u2

+v2

), and |x+iy| = √x2

+y2

尽管可能出现中间溢出。换句话说,程序员保证传递给这些函数的值的范围是有限的。默认值是OFF

非标准的编译指示

#pragma once

#pragma once是绝大多数现代编译器支持的非标准编译指示。如果它出现在头文件中,则表明它只是被解析一次,即使它被(直接或间接)多次包含在同一个源文件中。

标准的方法来防止多个包含相同的标题是通过使用包括守卫:

#ifndef FILENAME_H
#define FILENAME_H
// contents of the header
#endif /* FILENAME_H */

因此,任何翻译单元中除首标头以外的所有内容都不包含在汇编中。

#pragma once,相同的标题显示。

#pragma once
// contents of the header

与标头守卫不同,此附注使得不可能在多个文件中错误地使用相同的宏名称。另一方面,由于#pragma once基于文件系统级别的身份排除文件,如果它存在于项目中的多个位置,则无法防止包含头两次。

#pragma pack

参考

  • C11标准(ISO / IEC 9899:2011):
    • 6.10.9 Pragma算子(p:178)
  • C99标准(ISO / IEC 9899:1999):
    • 6.10.6 Pragma指令(p:159)
  • C89 / C90标准(ISO / IEC 9899:1990):
    • 3.8.6 Pragma指令

C 语法相关

1.#define directive
2.#elif directive
3.#else directive
4.#endif directive
5.#error directive
6.#if directive
7.#ifdef directive
8.#ifndef directive
9.#include directive
10.#line directive
11.alignas
12.Alternative operators and tokens
13.Analyzability
14.Arithmetic operators
15.Arithmetic types
16.Array declaration
17.Array initialization
18.ASCII Chart
19.Assignment operators
20. types
21.Basic concepts
22.Bit fields
23.break statement
24.C language
25.C Operator Precedence
26.cast operator
27.character constant
28.Comments
29.Comparison operators
30.compound literals
31.Conditional inclusion
32.Conformance
33.const type qualifier
34.Constant expressions
35.continue statement
36.Declarations
37.do-while loop
38.Enumerations
39.Escape sequences
40.Expressions
41.External and tentative definitions
42.File scope
43.floating constant
44.for loop
45.Function declarations
46.Function definitions
47.Functions
48.Generic selection
49.goto statement
50.Identifier
51.if statement
52.Implicit conversions
53.Increment/decrement operators
54.Initialization
55.inline function specifier
56.integer constant
57.Lifetime
58.Logical operators
59.Lookup and name spaces
60.Main function
61.Member access operators
62.Memory model
63.Objects and alignment
64.Order of evaluation
65.Other operators
66.Phases of translation
67.Pointer declaration
68.Preprocessor
69.restrict type qualifier
70.return statement
71.Scalar initialization
72.Scope
73.sizeof operator
74.Statements
75.static assert declaration
76.Static storage duration
77.Storage-class specifiers
78.string literals
79.Struct and union initialization
80.Struct declaration
81.switch statement
82.Thread storage duration
83.Type
84.Type
85.Typedef declaration
86.Undefined behavior
87.Union declaration
88.Value categories
89.Variadic arguments
90.volatile type qualifier
91.while loop
92._Alignof operator
93._Noreturn function specifier
C

C 语言是一门通用计算机编程语言,应用广泛。C 语言的设计目标是提供一种能以简易的方式编译、处理低级存储器、产生少量的机器码以及不需要任何运行环境支持便能运行的编程语言。