C语言一些容易忘得知识点汇总
- ### Designated Initializers (指定初始化)
C99 引入的新特性。可以直接初始化指定数组下标或者结构体某个成员。
struct S1 {
int i;
float f;
int a[2];
};
struct S1 x = {
.f=3.1,
.i=2,
.a[1]=9
};
int a[6] = { [4] = 29, [2] = 15 };
rohc-lib.org 里 rohc_traces.h 里 应用如下:
typedef enum
{
ROHC_TRACE_DEBUG = 0, /**< Print debug traces */
ROHC_TRACE_INFO = 1, /**< Print info (or lower) traces */
ROHC_TRACE_WARNING = 2, /**< Print warning (or lower) traces */
ROHC_TRACE_ERROR = 3, /**< Print error (or lower) traces */
ROHC_TRACE_LEVEL_MAX /**< The maximum number of trace levels */
} rohc_trace_level_t;
const char *level_descrs[] =
{
[ROHC_TRACE_DEBUG] = "DEBUG",
[ROHC_TRACE_INFO] = "INFO",
[ROHC_TRACE_WARNING] = "WARNING",
[ROHC_TRACE_ERROR] = "ERROR"
};
这样就方便改删调试信息了。
C99 已经可以在函数内随时随地需要用的时候再定义变量了,就像C++一样。
更多内容参考这里: The New C: Declarations & Initializations
C99