Hacker News
C/C++ Embedded Files (2013)
gavinray
|next
[-]
indigoabstract
|root
|parent
|next
[-]
I think in a few (3-4?) years it will be safe to use, but in any case not now.
Still, good to know that it exists.
gmueckl
|root
|parent
[-]
indigoabstract
|root
|parent
[-]
So as long as #embed isn't supported by all the 3 major compilers, I am sticking with my current embedding setup. I guess that's what I was thinking of.
jcalvinowens
|root
|parent
|next
|previous
[-]
monegator
|root
|parent
|next
|previous
[-]
jcelerier
|root
|parent
|next
[-]
rolandhvar
|root
|parent
|previous
[-]
> 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?
Calavar
|root
|parent
|next
[-]
The C++ standard says implementation defined because the weeds get very thick very quickly:
- Are paths formed with forward slash or backslash?
- Case sensitive?
- NT style drive letter or Posix style mounts?
- For relative paths, what is it relative to? When there are multiple matches, what is the algorithm to determine priority?
- What about symlinks and hard links?
- Are http and ftp URIs 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. 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 like command line options for specifying search paths and the strategy for long paths on Windows
What if #embed 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 standards conformant. You know that, I know that, we all know that. So why are we wasting words discussing it?
gmueckl
|root
|parent
|next
[-]
GabrielTFS
|root
|parent
|next
|previous
[-]
orbital223
|root
|parent
|next
|previous
[-]
How can you know that your Python implementation won't send your credit card details to an LLM when it runs your script? It does not follow an ISO standard that says it can't do that. You're not making assumptions about it's behavior, are you?
CamouflagedKiwi
|root
|parent
|next
|previous
[-]
afiori
|root
|parent
[-]
david2ndaccount
|root
|parent
|next
|previous
[-]
MoltenMan
|root
|parent
|next
|previous
[-]
CamouflagedKiwi
|next
|previous
[-]
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
|root
|parent
[-]
https://github.com/jcalvinowens/ircam-viewer/commit/17b3533b...
saidnooneever
|next
|previous
[-]
it might be a bit 'arcane' way to do it idk... but to me it always seemed the logical way.. u can also define symbols etc around it and use extern in ur c/cpp program to reference those.to access the data in light of dynamic linking / alsr etc.
here is some resource on it with some examples: https://wiki.osdev.org/Linker_Scripts
u can include any file. another executable, images, etc. etc. no need for weird stuff in the c sources?
on the flipside, is there a benefit of doing it inside the source code?? (apart from not having to roll ur own linker script and learn that dragon?)
Neywiny
|next
|previous
[-]
cyco130
|next
|previous
[-]
delduca
|next
|previous
[-]
``` inline constexpr auto bootstrap = #include "bootstrap.lua" ;
// ... later
lua.script(bootstrap, "@bootstrap"); ```
The lua code ``` R"( -- your code here )"; ```
mgaunard
|next
|previous
[-]
Regardless all of the methods suggested are terrible. If you don't have access to #embed, just write a trivial python script.
david2ndaccount
|root
|parent
|next
[-]
oguz-ismail2
|root
|parent
|previous
[-]
mgaunard
|root
|parent
[-]
Just write a Python script that does the whole thing.
oguz-ismail2
|root
|parent
|next
[-]
astrobe_
|root
|parent
|next
[-]
jcalvinowens
|root
|parent
|previous
[-]
oguz-ismail2
|root
|parent
|next
[-]
Is there any guarantee they won't break backwards compatibility again?
jcalvinowens
|root
|parent
[-]
Arguably it could be a little C helper, but I wanted this particular piece of the project to be more accessible so I used a scripting language.
array_key_first
|root
|parent
|previous
[-]
mgaunard
|root
|parent
|next
[-]
array_key_first
|root
|parent
[-]
Also, perl has other uses. Perl is much more competent at awk/sed/grep like tasks than python, and it can also be much faster. More people should be writing perl, imo. There's a ton of programs written in C that should just be perl.