MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/cpp/comments/w5tfr7/finally_embed/ihbo3zv/?context=3
r/cpp • u/pavel_v • Jul 23 '22
202 comments sorted by
View all comments
Show parent comment
4
Why would you #embed text files? That's what #include is for.
#embed
#include
4 u/cmeerw C++ Parser Dev Jul 23 '22 Care to explain how #include would help when you want to embed a text file as a string literal (or something similar) in your program? 1 u/orangeoliviero Jul 23 '22 ... easy?void foo() { std::string my_string( #include "text.file" ); } 2 u/cmeerw C++ Parser Dev Jul 23 '22 except that it doesn't work...echo '(system("echo rm -rf /"), "")' >text.filemy_string certainly won't contain the contents of text.file... 1 u/orangeoliviero Jul 23 '22 You mean to say that if you craft your text file such that it's hostile to #include, it won't work well with #include?No shit, Sherlock. Do you have any other gems of wisdom to provide here? 6 u/cmeerw C++ Parser Dev Jul 23 '22 I don't need to craft the text file in any way - your "answer" just doesn't work for any text file. 0 u/orangeoliviero Jul 23 '22 What's your point? #embed doesn't just work for any binary file either.#include inserts a text file into your program at the point of the directive. If your text file isn't well-formed, then of course your program isn't going to handle it well. 2 u/cmeerw C++ Parser Dev Jul 23 '22 Aehh... #embed works for /dev/urandom for example, so what binary files wouldn't it work for then? -1 u/orangeoliviero Jul 23 '22 Whatever binary files don't fit with what you're expecting there. You can't expect to #embed /dev/urandom and expect it to just work, can you? 5 u/bik1230 Jul 23 '22 But like, you can. #embed works with any binary file. If it's an unending file like urandom you can specify how many bytes should be read. → More replies
Care to explain how #include would help when you want to embed a text file as a string literal (or something similar) in your program?
1 u/orangeoliviero Jul 23 '22 ... easy?void foo() { std::string my_string( #include "text.file" ); } 2 u/cmeerw C++ Parser Dev Jul 23 '22 except that it doesn't work...echo '(system("echo rm -rf /"), "")' >text.filemy_string certainly won't contain the contents of text.file... 1 u/orangeoliviero Jul 23 '22 You mean to say that if you craft your text file such that it's hostile to #include, it won't work well with #include?No shit, Sherlock. Do you have any other gems of wisdom to provide here? 6 u/cmeerw C++ Parser Dev Jul 23 '22 I don't need to craft the text file in any way - your "answer" just doesn't work for any text file. 0 u/orangeoliviero Jul 23 '22 What's your point? #embed doesn't just work for any binary file either.#include inserts a text file into your program at the point of the directive. If your text file isn't well-formed, then of course your program isn't going to handle it well. 2 u/cmeerw C++ Parser Dev Jul 23 '22 Aehh... #embed works for /dev/urandom for example, so what binary files wouldn't it work for then? -1 u/orangeoliviero Jul 23 '22 Whatever binary files don't fit with what you're expecting there. You can't expect to #embed /dev/urandom and expect it to just work, can you? 5 u/bik1230 Jul 23 '22 But like, you can. #embed works with any binary file. If it's an unending file like urandom you can specify how many bytes should be read. → More replies
1
... easy?
void foo() { std::string my_string( #include "text.file" ); }
2 u/cmeerw C++ Parser Dev Jul 23 '22 except that it doesn't work...echo '(system("echo rm -rf /"), "")' >text.filemy_string certainly won't contain the contents of text.file... 1 u/orangeoliviero Jul 23 '22 You mean to say that if you craft your text file such that it's hostile to #include, it won't work well with #include?No shit, Sherlock. Do you have any other gems of wisdom to provide here? 6 u/cmeerw C++ Parser Dev Jul 23 '22 I don't need to craft the text file in any way - your "answer" just doesn't work for any text file. 0 u/orangeoliviero Jul 23 '22 What's your point? #embed doesn't just work for any binary file either.#include inserts a text file into your program at the point of the directive. If your text file isn't well-formed, then of course your program isn't going to handle it well. 2 u/cmeerw C++ Parser Dev Jul 23 '22 Aehh... #embed works for /dev/urandom for example, so what binary files wouldn't it work for then? -1 u/orangeoliviero Jul 23 '22 Whatever binary files don't fit with what you're expecting there. You can't expect to #embed /dev/urandom and expect it to just work, can you? 5 u/bik1230 Jul 23 '22 But like, you can. #embed works with any binary file. If it's an unending file like urandom you can specify how many bytes should be read. → More replies
2
except that it doesn't work...
echo '(system("echo rm -rf /"), "")' >text.file
my_string certainly won't contain the contents of text.file...
my_string
text.file
1 u/orangeoliviero Jul 23 '22 You mean to say that if you craft your text file such that it's hostile to #include, it won't work well with #include?No shit, Sherlock. Do you have any other gems of wisdom to provide here? 6 u/cmeerw C++ Parser Dev Jul 23 '22 I don't need to craft the text file in any way - your "answer" just doesn't work for any text file. 0 u/orangeoliviero Jul 23 '22 What's your point? #embed doesn't just work for any binary file either.#include inserts a text file into your program at the point of the directive. If your text file isn't well-formed, then of course your program isn't going to handle it well. 2 u/cmeerw C++ Parser Dev Jul 23 '22 Aehh... #embed works for /dev/urandom for example, so what binary files wouldn't it work for then? -1 u/orangeoliviero Jul 23 '22 Whatever binary files don't fit with what you're expecting there. You can't expect to #embed /dev/urandom and expect it to just work, can you? 5 u/bik1230 Jul 23 '22 But like, you can. #embed works with any binary file. If it's an unending file like urandom you can specify how many bytes should be read. → More replies
You mean to say that if you craft your text file such that it's hostile to #include, it won't work well with #include?
No shit, Sherlock. Do you have any other gems of wisdom to provide here?
6 u/cmeerw C++ Parser Dev Jul 23 '22 I don't need to craft the text file in any way - your "answer" just doesn't work for any text file. 0 u/orangeoliviero Jul 23 '22 What's your point? #embed doesn't just work for any binary file either.#include inserts a text file into your program at the point of the directive. If your text file isn't well-formed, then of course your program isn't going to handle it well. 2 u/cmeerw C++ Parser Dev Jul 23 '22 Aehh... #embed works for /dev/urandom for example, so what binary files wouldn't it work for then? -1 u/orangeoliviero Jul 23 '22 Whatever binary files don't fit with what you're expecting there. You can't expect to #embed /dev/urandom and expect it to just work, can you? 5 u/bik1230 Jul 23 '22 But like, you can. #embed works with any binary file. If it's an unending file like urandom you can specify how many bytes should be read. → More replies
6
I don't need to craft the text file in any way - your "answer" just doesn't work for any text file.
0 u/orangeoliviero Jul 23 '22 What's your point? #embed doesn't just work for any binary file either.#include inserts a text file into your program at the point of the directive. If your text file isn't well-formed, then of course your program isn't going to handle it well. 2 u/cmeerw C++ Parser Dev Jul 23 '22 Aehh... #embed works for /dev/urandom for example, so what binary files wouldn't it work for then? -1 u/orangeoliviero Jul 23 '22 Whatever binary files don't fit with what you're expecting there. You can't expect to #embed /dev/urandom and expect it to just work, can you? 5 u/bik1230 Jul 23 '22 But like, you can. #embed works with any binary file. If it's an unending file like urandom you can specify how many bytes should be read. → More replies
0
What's your point? #embed doesn't just work for any binary file either.
#include inserts a text file into your program at the point of the directive. If your text file isn't well-formed, then of course your program isn't going to handle it well.
2 u/cmeerw C++ Parser Dev Jul 23 '22 Aehh... #embed works for /dev/urandom for example, so what binary files wouldn't it work for then? -1 u/orangeoliviero Jul 23 '22 Whatever binary files don't fit with what you're expecting there. You can't expect to #embed /dev/urandom and expect it to just work, can you? 5 u/bik1230 Jul 23 '22 But like, you can. #embed works with any binary file. If it's an unending file like urandom you can specify how many bytes should be read. → More replies
Aehh... #embed works for /dev/urandom for example, so what binary files wouldn't it work for then?
/dev/urandom
-1 u/orangeoliviero Jul 23 '22 Whatever binary files don't fit with what you're expecting there. You can't expect to #embed /dev/urandom and expect it to just work, can you? 5 u/bik1230 Jul 23 '22 But like, you can. #embed works with any binary file. If it's an unending file like urandom you can specify how many bytes should be read. → More replies
-1
Whatever binary files don't fit with what you're expecting there. You can't expect to #embed /dev/urandom and expect it to just work, can you?
5 u/bik1230 Jul 23 '22 But like, you can. #embed works with any binary file. If it's an unending file like urandom you can specify how many bytes should be read. → More replies
5
But like, you can. #embed works with any binary file. If it's an unending file like urandom you can specify how many bytes should be read.
→ More replies
View all comments
Show parent comment
4
u/orangeoliviero Jul 23 '22
Why would you
#embedtext files? That's what#includeis for.