Sujet : Re: C23 thoughts and opinions
De : bc (at) *nospam* freeuk.com (bart)
Groupes : comp.lang.cDate : 30. May 2024, 14:34:00
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v39v87$1n7bk$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
User-Agent : Mozilla Thunderbird
On 30/05/2024 03:32, Lawrence D'Oliveiro wrote:
On Wed, 29 May 2024 13:58:20 +0200, Bonita Montero wrote:
I've got a small commandline-tool that makes a const'd char
-array from any binary file.
It seems to me it would be more efficient to use objcopy to turn that
binary file directly into an object file with symbols accessible from C
code defining its beginning and ending points. Then just link it into the
executable.
None of my compilers, whether for C or anything else, generate object files.
However, suppose I wanted to link a file called 'logo.bmp' say, into my program, which consisted of a file called main.c.
What is the entire process using your suggestion? What do I put into main.c? Assume the data is represented by a char-array.
In my language, it would simply be this:
[]byte logobmp = binclude("logo.bmp")
Using my C extension, it might be this:
uint8_t logobmp[] = strinclude("logo.bmp");
(I believe this will cope with embedded zeros, and the file size is obtainable with 'sizeof(logobmp)'.
With the new feature it might be this (I forget the exact syntax):
uint8_t logobmp[] = {
#embed "logo.bmp"
};
Nothing else is needed; just compile as normal.
The point of the feature is avoid the palavar with 'objcopy', which is a utility with 100 different options, or messing with ones like xxd.