LLVM Clang 19 Lands Support For C23's #embed
([LLVM] 6 Hours Ago
C23 #embed)
- Reference: 0001470247
- News link: https://www.phoronix.com/news/LLVM-Clang-19-C23-Embed
- Source link:
Merged today to LLVM Clang 19 Git is support for the #embed resource inclusion mechanism that is an approved C23 feature. This also makes Clang the first for supporting this pre-processor embed feature.
C23's #embed pre-processor directive makes it easy to include binary data within an executable. With C23 #embed the developer can include the contents of an external binary file at compile-time without relying on any external approaches or resorting to loading the external binary file(s) at run-time.
More details on the C23 #embed feature can be found via the [1]open-std.org whitepaper on the feature. The abstract is as follows:
"Pulling binary data into a program often involves external tools and build system coordination. Many programs need binary data such as images, encoded text, icons and other data in a specific format. Current state of the art for working with such static data in C includes creating files which contain solely string literals, directly invoking the linker to create data blobs to access through carefully named extern variables, or generating large brace-delimited lists of integers to place into arrays. As binary data has grown larger, these approaches have begun to have drawbacks and issues scaling. From parsing 5 megabytes worth of integer literal expressions into AST nodes to arbitrary string literal length limits in compilers, portably putting binary data in a C program has become an arduous task that taxes build infrastructure and compilation memory and time. This proposal provides a flexible preprocessor directive for making this data available to the user in a straightforward manner."
Since last year has been [2]this pull request making all the necessary changes to support the #embed pre-processor for both C and C++. After months of work, that code was merged this morning and now makes LLVM Clang the first of the major open-source compilers supporting this directive.
The current C23 language status with the Clang compiler can be found via [3]this status page .
[1] https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3017.htm
[2] https://github.com/llvm/llvm-project/pull/68620
[3] https://clang.llvm.org/c_status.html#c2x
C23's #embed pre-processor directive makes it easy to include binary data within an executable. With C23 #embed the developer can include the contents of an external binary file at compile-time without relying on any external approaches or resorting to loading the external binary file(s) at run-time.
More details on the C23 #embed feature can be found via the [1]open-std.org whitepaper on the feature. The abstract is as follows:
"Pulling binary data into a program often involves external tools and build system coordination. Many programs need binary data such as images, encoded text, icons and other data in a specific format. Current state of the art for working with such static data in C includes creating files which contain solely string literals, directly invoking the linker to create data blobs to access through carefully named extern variables, or generating large brace-delimited lists of integers to place into arrays. As binary data has grown larger, these approaches have begun to have drawbacks and issues scaling. From parsing 5 megabytes worth of integer literal expressions into AST nodes to arbitrary string literal length limits in compilers, portably putting binary data in a C program has become an arduous task that taxes build infrastructure and compilation memory and time. This proposal provides a flexible preprocessor directive for making this data available to the user in a straightforward manner."
Since last year has been [2]this pull request making all the necessary changes to support the #embed pre-processor for both C and C++. After months of work, that code was merged this morning and now makes LLVM Clang the first of the major open-source compilers supporting this directive.
The current C23 language status with the Clang compiler can be found via [3]this status page .
[1] https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3017.htm
[2] https://github.com/llvm/llvm-project/pull/68620
[3] https://clang.llvm.org/c_status.html#c2x
ssokolow