Recommended practice: A mechanism similar to, but distinct from, the
implementation-defined
search paths used for #include ([cpp.include])
is encouraged.
The #embed directive is replaced by a comma-delimited list of integer
literals of type int, unless otherwise modified by embed
parameters ([cpp.embed.param]).
The integer literals in the comma-delimited list correspond to
resource-count consecutive calls to std::fgetc ([cstdio.syn])
from the resource, as a binary file.
If any call to std::fgetc returns EOF, the program is
ill-formed.
Recommended practice: The value of each integer literal should closely represent
the bit stream of the resource unmodified.
This can require an implementation to consider potential differences between
translation and execution environments, as well as any other applicable
sources of mismatch.
[Example 2: #include<cstring>#include<cstddef>#include<fstream>#include<vector>#include<cassert>int main(){// If the file is the same as the resource in the translation environment, no assert in this program should fail.constexprunsignedchar d[]={#embed <data.dat>};
const std::vector<unsignedchar> vec_d ={#embed <data.dat>};
constexpr std::size_t expected_size =sizeof(d);
// same file in execution environment as was embedded
std::ifstream f_source("data.dat", std::ios::binary | std::ios::in);
unsignedchar runtime_d[expected_size];
char* ifstream_ptr =reinterpret_cast<char*>(runtime_d);
assert(!f_source.read(ifstream_ptr, expected_size));
std::size_t ifstream_size = f_source.gcount();
assert (ifstream_size == expected_size);
int is_same = std::memcmp(&d[0], ifstream_ptr, ifstream_size);
assert(is_same ==0);
int is_same_vec = std::memcmp(vec_d.data(), ifstream_ptr, ifstream_size);
assert(is_same_vec ==0);
} — end example]
[Example 3: int i ={#embed "i.dat"}; // well-formed if i.dat produces a single valueint i2 =#embed "i.dat"
; // also well-formed if i.dat produces a single valuestruct s {double a, b, c;
struct{double e, f, g; } x;
double h, i, j;
};
s x ={// well-formed if the directive produces nine or fewer values#embed "s.dat"};
— end example]
(that does not match one of the two previous forms) is permitted.
The preprocessing tokens after embed in the directive are processed
just as in normal text (i.e., each identifier currently defined as a macro
name is replaced by its replacement list of preprocessing tokens).
The directive resulting after all replacements of the third form shall match
one of the two previous forms.
The method by which a sequence of preprocessing tokens between a < and
a > preprocessing token pair or a pair of " characters is
combined into a single resource name preprocessing token is
implementation-defined.