liveBook · Manning

__has_embed

As explained in Modern C, Third Edition

__has_embed is a C23 preprocessing feature that tests whether a specified file can be embedded.

__has_embed is a C23 preprocessing feature for testing binary-file embedding. First test whether __has_embed is defined; then call __has_embed("picture.dat") in a preprocessor condition to determine whether that file can be embedded. section 14.6

Guard an embedded initializer

unsigned char logo[] = {\n#if defined(__has_embed) && __has_embed("picture.dat")\n# embed "picture.dat"\n#else\n "embed directive is missing"\n#endif\n};\n\nWhen supported and available, #embed supplies the file's bytes as comma-separated decimal values suitable for initializing logo; otherwise the fallback text is used. section 14.6

How Modern C, Third Edition covers it

How deep it goes
Explains implementation detection and the result value, while leaving byte-list generation to #embed.
Examples
Uses picture.dat to initialize logo and a fallback string when embedding support or the file is unavailable.
What you can do after
Apply it via preprocessor conditions to select embedded binary data or a fallback initializer.
How it connects
Connects __has_embed with #embed directives, preprocessor conditions, binary streams, and array initializers.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C, Third Edition. The section links point to the parts of the book it draws on.