Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: bart Newsgroups: comp.lang.c Subject: Re: C23 thoughts and opinions Date: Thu, 30 May 2024 14:34:00 +0100 Organization: A noiseless patient Spider Lines: 42 Message-ID: References: <00297443-2fee-48d4-81a0-9ff6ae6481e4@gmail.com> <87msoh5uh6.fsf@nosuchdomain.example.com> <87y18047jk.fsf@nosuchdomain.example.com> <87msoe1xxo.fsf@nosuchdomain.example.com> <87ikz11osy.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 30 May 2024 15:34:00 +0200 (CEST) Injection-Info: dont-email.me; posting-host="8c5499e5d518415769692484ec9a1979"; logging-data="1809780"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19RzNvQEURwkj6M8zQj/RTY" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:pdldldNeCpYwN/dw6B1Y05PlHxo= In-Reply-To: Content-Language: en-GB Bytes: 3081 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.