frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

C/C++ Embedded Files (2013)

https://www.4rknova.com//blog/2013/01/27/cpp-embedded-files
27•ibobev•1h ago

Comments

gavinray•1h ago
Outdated, modern solution is baked in now

https://en.cppreference.com/w/c/preprocessor/embed

rolandhvar•1h ago
The thing that always irks me about c++ is this sort of thing:

> Explanation 1) Searches for the resource identified by h-char-sequence in implementation-defined manner.

Okay, so now I have to make assumptions that the implementation is reasonable, and won't go and "search" by asking an LLM or accidentally revealing my credit card details to a third party, right?

And even if the implementation _is_ reasonable the only way I know what "search" means in this context is by looking at an example, and the example says "it's basically a filename".

So now I think to myself: if I want to remain portable, I'll just write a python script to do a damn substitution to embed my file, which is guaranteed to work under _any_ implementation and I don't have to worry about it as soon as I have my source file.

Does anyone else feel this way or is it just me?

MoltenMan•1h ago
...what? What are you talking about? In what world would a compiler implement a preprocessor directive to ever use an llm, the internet, or your credit card details (from where would it get those)??? There are always implementation defined things in every language, for example, ub behavior. Do you get worried that someone will steal your bitcoin every time you use after free? Of course not! Even in Python when you OOM -- at least in CPython -- you crash with undefined behavior.
MoltenMan•1h ago
Sorry for being so aggressive. I suppose I'm just very confused at where you're coming from.
CamouflagedKiwi•1h ago
This doesn't sound like the kind of portability anyone is really worried about. I get that the docs on the linked site are written in standards-ese and are complicated by macro replacement, but I don't think the outcome of sending your credit card details away is gonna be an outcome. If it was, an uncharitable implementation with access to your card details would be free to do that any time you gave it input invoking undefined behaviour (which is of course not uncommon, especially in incorrect code).
david2ndaccount•46m ago
If you want to remain portable, write your code in the intersection of the big 3 - GCC, Clang and MSVC - and you’ll be good enough. Other implementations will either be weird enough that many things you’d expect to work won’t or are forced to copy what those 3 do anyway.
Calavar•13m ago
You're not the only one who feels that way, but IMHO it's not avalid complaint.

The C++ standard says implementation defined because the weeds get very thick here:

- Are paths formed with forward slash or backslash?

- Case sensitive?

- NT style drive letter or Posix style root dir?

- For relative paths, what is it relative to? When there all multiple matches, what is the algorithm to determine priority?

- What about symlinks and hard links?

- Are http and ftp URI's supported (e.g. an online IDE like godbolt). If so, which versions of those protocols? TLS 1.3+ only? Are you going to accept SHA-1?

- Should the file read be transactional?

People already complain that the C++ standard is overly complicated by one or two orders of mangitude more than it should be. So instead of adding even more complexity by redefining the OS semantics of your build platform in a language spec, they use "implementation defined" as a shorthand for "your compiler will call fopen" plus some implementation wiggle room

What if steals my credit card data is a pointless strawman. If a malicious compiler dev wanted to steal your credit card data, they'd just inject the malicious code; not act like a genie, searching the C++ spec with a fine comb for a place where they could execute malicious code while still *technically* being stanards conformant. You know that, I know what, we all know that. So why are we wasting words discussing it?

monegator•38m ago
let me know when my embedded target's compiler is C23 compliant (i mean, i whish. we may be getting C11 or even C17 some times next year but i'm not holding my breath)
jcalvinowens•37m ago
It will be at least a decade before I can rely on that in systems software that needs to be portable.
mgaunard•1h ago
surely the preprocessor method doesn't work in the general case, since the data can contain commas or parentheses.

Regardless all of the methods suggested are terrible. If you don't have access to #embed, just write a trivial python script.

oguz-ismail2•1h ago
How is `xxd -i' terrible?
mgaunard•53m ago
It's still lacking content that goes before/after the output.

Just write a Python script that does the whole thing.

oguz-ismail2•49m ago
Don't know what you mean, it works fine here. Python is too large and unreliable a dependency for something so trivial (which can be accomplished using standard POSIX utilities if need be).
jcalvinowens•29m ago
Python is pretty much mandatory for Linux systems nowadays, unless you're dealing with something really minimalist or trying to be very portable it's safe to rely on.
oguz-ismail2•15m ago
> it's safe to rely on

Is there any guarantee they won't break backwards compatibility again?

astrobe_•25m ago
Indeed, even writing this utility in C is trivial and has 0 extra dependency for a pure C/C++ project. Avoiding #embed also removes the dependency to a C++23 capable compiler, which might not be available in uncommon scenarios.
david2ndaccount•48m ago
You can apply `#` to __VA_ARGS__, which won’t preserve the exact whitespace, but for many languages it’s good enough. biggest issue is you can’t have `#` in the text.
CamouflagedKiwi•1h ago
You can also do it using ld - it's something like ld -r --format binary -o out.o <file>, although you do want some build system assistance to generate header files allowing you to access the thing (somewhat similar to the assembly example here). It's a bit of a performance but I strongly prefer it to generating header files in the earlier options - those header files can end up being _very_ large (they generally multiply up the size of the embedded file by 2-4x) and slow to compile.

All a bit less relevant now since recent C++ versions have this built in by default. Generally something languages have been IMO too slow on (e.g. Go picked this up four or so years ago, after a bunch of less nice home-grown alternatives), it's actually just really useful to make things work in the real world, especially for languages that you can distribute as single-file binaries (which IMO should be all of them, but sadly it's not always).

jcalvinowens•43m ago
The special ld argument is a gnu thing, it's not portable and at least lld doesn't support it.

https://github.com/jcalvinowens/ircam-viewer/commit/17b3533b...

borcunozkablan•1h ago
Why don't you #embed?
qbow883•38m ago
Because the linked article is from 2013.
delduca•45m ago
My current workaround until it arrives in all C++ compilers

``` inline constexpr auto bootstrap = #include "bootstrap.lua" ;

// ... later

lua.script(bootstrap, "@bootstrap"); ```

The lua code ``` R"( -- your code here )"; ```

Daphne Oram, a visionary pioneer in electronic music

https://theconversation.com/5-things-to-know-about-daphne-oram-the-visionary-pioneer-in-electroni...
1•binning•1m ago•0 comments

Lewis Carroll Computed Determinants

https://www.johndcook.com/blog/2023/07/10/lewis-carroll-determinants/
1•tzury•1m ago•0 comments

Claude Bootstrap – Opinionated Project Initialization for Claude Code

https://github.com/alinaqi/claude-bootstrap
1•naxmax•2m ago•1 comments

University threatened with legal action after protest at academic's talk

https://www.bbc.co.uk/news/articles/cwyx3y84ln9o
1•binning•3m ago•0 comments

Show HN: AI Directories – Submit your AI tool to 300 directories (2 minutes)

https://300aidirectories.com
1•HansP958•3m ago•0 comments

One-Stop Publication Workbench – Zettlr

https://www.zettlr.com
1•Tomte•4m ago•0 comments

Using the Problem to Solve the Problem

https://marcosvpj.com.br/en/posts/using-the-problem-to-solve-the-problem/
1•marcosvpj•5m ago•0 comments

Windows Recall

https://en.wikipedia.org/wiki/Windows_Recall
1•CGMthrowaway•5m ago•0 comments

BTC3 – A Fast, Self-Contained Bitcoin Testnet

https://github.com/cgebitcoin/btc3
1•cgebitcoin•8m ago•1 comments

Ask HN: Is Dart a particularly optimised language for front-end development?

1•theanonymousone•9m ago•0 comments

Can an Auto-Generated Forensic Report Hold Up in Court?

1•cd_mkdir•16m ago•0 comments

AI is a motorbike for the mind – not always a good thing

https://kau.sh/blog/motorbike-for-the-mind/
2•sorcercode•17m ago•0 comments

The Radicalization of My Father

https://vomtag.com/entry/The-Radicalization-of-my-Father
2•saltysalt•19m ago•2 comments

Show HN: Twine – A tool to dynamically trace calls in production Elixir systems

https://github.com/ollien/twine
2•todsacerdoti•19m ago•0 comments

Rob Pike got spammed with an AI slop "act of kindness"

https://simonwillison.net/2025/Dec/26/slop-acts-of-kindness/
12•nabla9•22m ago•1 comments

"DevOps didn't exist when I started as a developer."

https://circleci.com/blog/devops-did-not-exist/
1•fanf2•23m ago•0 comments

Sometimes, the quiet achievements are the most important ones

https://herbertlui.net/sometimes-the-quiet-achievements-are-the-most-important-ones/
1•herbertl•31m ago•0 comments

Ask HN: Change my mind) should AI coding conversations be append-only?

1•wsxiaoys•32m ago•1 comments

Oracle stock on pace for worst quarter since 2001, AI concerns

https://www.cnbc.com/2025/12/26/oracle-stock-on-pace-for-worst-quarter-since-2001-ai-concerns.html
4•speckx•33m ago•0 comments

The Secret Service Agent Haunted by His Failure to Save JFK

https://www.nytimes.com/interactive/2025/12/16/magazine/clint-hill-jfk-secret-service.html
1•bookofjoe•35m ago•1 comments

Cursed circuits #4: PLL frequency multiplier

https://lcamtuf.substack.com/p/cursed-circuits-4-pll-frequency-multiplier
3•ArmageddonIt•40m ago•1 comments

Show HN: A small embeddable and hackable Lisp-2 interpreter in C

https://github.com/mistivia/bamboo-lisp
2•mistivia•42m ago•0 comments

Elevator Wiki: wiki about elevators and their related topics

https://elevation.fandom.com/wiki/Elevator_Wiki
2•thunderbong•44m ago•0 comments

Star Guage

https://en.wikipedia.org/wiki/Star_Gauge
1•nz•44m ago•0 comments

Resolve merge conflicts with Claude Code

https://raine.dev/blog/resolve-conflicts-with-claude/
1•rane•44m ago•0 comments

Tixl: Open-source realtime motion graphics

https://github.com/tixl3d/tixl
1•nateb2022•44m ago•0 comments

Show HN: An authority gate for AI-generated customer communication

https://authority.bhaviavelayudhan.com
2•bhaviav100•47m ago•3 comments

MongoBleed

https://github.com/joe-desimone/mongobleed/blob/main/mongobleed.py
2•gpi•48m ago•0 comments

Gh-yule-log: GitHubCLI extension turns your terminal into an animated Yule log

https://github.com/leereilly/gh-yule-log
1•nateb2022•48m ago•0 comments

BitVault – A time-delayed multisig Wallet Solution delivering utmost security

https://www.bitvault.sv/
1•bitvaulty•53m ago•1 comments