Sujet : Re: C23 thoughts and opinions
De : bc (at) *nospam* freeuk.com (bart)
Groupes : comp.lang.cDate : 27. May 2024, 14:03:16
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v320am$1km5$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
User-Agent : Mozilla Thunderbird
On 27/05/2024 03:48, Lawrence D'Oliveiro wrote:
On Mon, 27 May 2024 01:55:24 +0100, bart wrote:
On 27/05/2024 01:44, Lawrence D'Oliveiro wrote:
Nothing “unwieldy” about it. It’s a bunch of temporary intermediate build
products, generated from suitable source files like everything else in the
build.
It only solves the easy part: including that binary data in the build.
>
Apparently that is not so easy as you seem to think.
Yes, it is as easy as I think. I’ve done this sort of thing, using
suitable build scripts.
Show me.
This is how I show help text, which is maintained in an ordinary text file, from within my C compiler:
println sinclude("help.txt")
Just one line directly in the source code. The text is baked in to the executable so there is no discrete file in the installation.
What would it look like in your build system, and what does it look like in the source code of your app?
I mean, it's not as though this stuff is impossible without such a feature; the idea is to make it much simpler to do.
If your method is simpler, I'll get rid of my feature and use your way.
BTW here is the entire build process for the compiler:
C:\cx>mm cc
Compiling cc.m to cc.exe
'cc' is cc.m, the lead module. It incorporates 42 embedded files in all. Your method can't be any more elaborate than that.
I don't use build scripts; I don't need them.
Here is another example using C (using an older compiler that supported embedded text files; this is not standard C, but it could be, and I think will be using #embed).
It is a program posted by Michael S, but with an extra 'puts' line at the beginning so that it first prints out its own source code.
It works by embedded the text for itself within the binary. I'd be interested in how your build process manages this.
----------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main(int argz, char** argv)
{
puts(strinclude(__FILE__));
if (argz > 1) {
FILE* fp = fopen(argv[1], "wb");
if (fp) {
char buf[2048];
_Bool look_for_comma = 0;
for (;;) {
if (fgets(buf, sizeof(buf), stdin) != buf)
break;
char* p = buf;
for (;;) {
char c = *p;
if (isgraph(c)) {
if (look_for_comma) {
if (c == ',') {
look_for_comma = 0;
++p;
} else {
goto done;
}
} else {
char* endp;
long val = strtol(p, &endp, 0);
if (endp==p) // not a number
goto done;
fputc((unsigned char)val, fp);
p = endp;
look_for_comma = 1;
}
} else {
if (c == 0)
break; // end of line
++p; // skip space or control character
}
}
}
done:
fclose(fp);
} else {
perror(argv[1]);
return 1;
}
}
return 0;
}
----------------------------------
C:\c>bcc c.c
Compiling c.c to c.exe
C:\c>c
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main(int argz, char** argv)
{
puts(strinclude(__FILE__));
if (argz > 1) {
FILE* fp = fopen(argv[1], "wb");
if (fp) {
.....
Or maybe you think
that 'embedding a file' just means adding it to a zip file?
It’s whatever “including it in the build” means. It might indeed be a zip
component, as with resources for an Android app. Or it might be converted
into an object file with a tool like objcopy, to be integrated into the
executable.
Embedding applies also to text files not just binaries.
Same principle applies.