[cpp.embed.param] (original) (raw)

15 Preprocessing directives [cpp]

15.4 Resource inclusion [cpp.embed]

15.4.2 Embed parameters [cpp.embed.param]

15.4.2.1 limit parameter [cpp.embed.param.limit]

[Example 1: #undef DATA_LIMIT#if __has_embed(<data.dat> limit(DATA_LIMIT)) #endif

#if __has_embed(<data.dat> limit(0)) #endif — _end example_]

[Example 2: #embed <data.dat> limit(__has_include("a.h")) #if __has_embed(<data.dat> limit(__has_include("a.h"))) #endif — _end example_]

The constant-expression shall be an integral constant expression whose value is greater than or equal to zero.

[Example 3: constexpr unsigned char sound_signature[] = { #embed <sdk/jump.wav> limit(2+2) };static_assert(sizeof(sound_signature) == 4); — _end example_]

15.4.2.3 suffix parameter [cpp.embed.param.suffix]

Otherwise, the pp-balanced-token-seq is placed immediately after the comma-delimited list of the integral constant expressions.

[Example 1: constexpr unsigned char whl[] = { #embed "ches.glsl" \ prefix(0xEF, 0xBB, 0xBF, ) \ suffix(,) 0 };constexpr bool is_empty = sizeof(whl) == 1 && whl[0] == '\0';constexpr bool is_not_empty = sizeof(whl) >= 4 && whl[sizeof(whl) - 1] == '\0' && whl[0] == '\xEF' && whl[1] == '\xBB' && whl[2] == '\xBF';static_assert(is_empty || is_not_empty); — _end example_]

15.4.2.4 if_empty parameter [cpp.embed.param.if.empty]

[Example 1:

limit(0) affects when a resource is considered empty.

Therefore, the following program:

#embed </owo/uwurandom> \ if_empty(42203) limit(0) expands to42203

— _end example_]

[Example 2:

This resource is considered empty due to the limit(0) embed-parameter, always, including in __has_embed clauses.

int infinity_zero () { #if __has_embed(</owo/uwurandom> limit(0) prefix(some tokens)) == __STDC_EMBED_EMPTY__return 0;#else #error "The resource does not exist" #endif } — _end example_]