Liste des Groupes | Revenir à cl c |
Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:That is what you would expect by the way #embed is specified. You would not expect to see any "optimisation", since optimisations should not change the results (apparent from choosing between alternative valid results).David Brown <david.brown@hesbynett.no> writes:I've built this from source, and it mostly works. I haven't seen it doOn 23/05/2024 14:11, bart wrote:[...][...]'embed' was discussed a few months ago. I disagreed with the poor>
way it was to be implemented: 'embed' notionally generates a list of
comma-separated numbers as tokens, where you have to take care of
any trailing zero yourself if needed. It would also be hopelessly
inefficient if actually implemented like that.
Fortunately, it is /not/ actually implemented like that - it is only
implemented "as if" it were like that. Real prototype implementations
(for gcc and clang - I don't know about other tools) are extremely
efficient at handling #embed. And the comma-separated numbers can be
more flexible in less common use-cases.
>
I'm aware of a proposed implementation for clang:
>
https://github.com/llvm/llvm-project/pull/68620
https://github.com/ThePhD/llvm-project
>
I'm currently cloning the git repo, with the aim of building it so I can
try it out and test some corner cases. It will take a while.
>
I'm not aware of any prototype implementation for gcc. If you are, I'd
be very interested in trying it out.
>
(And thanks for starting this thread!)
any optimization; the `#embed` directive expands to a sequence of
comma-separated integer constants.
Which means that this:
#include <stdio.h>
int main(void) {
struct foo {
unsigned char a;
unsigned short b;
unsigned int c;
double d;
};
struct foo obj = {
#embed "foo.dat"
};
printf("a=%d b=%d c=%d d=%f\n", obj.a, obj.b, obj.c, obj.d);
}
given "foo.dat" containing bytes with values 1, 2, 3, and 4, produces
this output:
a=1 b=2 c=3 d=4.000000
Les messages affichés proviennent d'usenet.