news.volyx.in

Embed is in C23 (thephd.dev)

483 points by aw1621107 · 1511 days ago · 338 comments on HN

Article summary

The C23 standard now includes the #embed directive, which allows developers to embed binary data directly into their executables. This feature has been a long time coming, with the author spending nearly 5 years advocating for its inclusion. The directive generates a comma-delimited list of integers, which can be used to initialize a static variable. This feature is expected to simplify build pipelines and improve performance.

Main themes

  • C23 standard
  • binary data embedding
  • build pipeline simplification
  • performance improvement
  • reproducible builds
  • compiler optimization
  • portability and compatibility
  • language standardization and evolution

What commenters say

  • Embedding binary data directly into executables can simplify build pipelines and improve performance.
  • The #embed directive is a useful feature that has been a long time coming, and its inclusion in C23 is a significant improvement.
  • Some developers have been using alternative methods, such as xxd, to embed binary data, but these methods have limitations and are not portable.
  • The inclusion of #embed in C23 may not be sufficient, as it does not address the needs of C++ developers, who may still have to use other methods to achieve similar results.
  • The use of #embed may have implications for reproducible builds, particularly when used with infinite files like /dev/urandom.
  • The compiler's as-if rule allows it to optimize the embedding process, making it more efficient than alternative methods.
  • The #embed directive is not without its limitations, and some developers may still prefer to use other methods, such as xxd, for certain use cases.