【发布时间】:2022-11-30 09:01:10
【问题描述】:
即将推出的 C23 标准中提供了一个新的预处理器指令:#embed
这是一个简单的例子:
// Placing a small image resource.
#include <stddef.h>
void show_icon(const unsigned char *, size_t);
int main (int, char*[]) {
static const unsigned char icon_data[] = {
#embed "black_sheep.ico"
};
show_icon(icon_data, sizeof(icon_data));
return 0;
}
这是一个更详细的从二进制数据初始化非数组(不管是什么意思):
int main() {
/* Braces may be kept or elided as per normal initialization rules */
int i = {
#embed "i.dat"
}; /* i value is [0, 2^(embed element width)) first entry */
int i2 =
#embed "i.dat"
; /* valid if i.dat produces 1 value, i2 value is [0, 2^(embed element width)) */
struct s {
double a, b, c;
struct { double e, f, g; };
double h, i, j;
};
struct s x = {
/* initializes each element in order according to
initialization rules with comma-separated list
of integer constant expressions inside of braces */
#embed "s.dat"
};
return 0;
}
把这个加入到C语言中的目的是什么?
【问题讨论】:
标签: c language-lawyer c23