Deutsch English Français Italiano |
<v3fr28$2tmmv$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: bart <bc@freeuk.com> Newsgroups: comp.lang.c Subject: Re: C23 thoughts and opinions Date: Sat, 1 Jun 2024 19:59:19 +0100 Organization: A noiseless patient Spider Lines: 104 Message-ID: <v3fr28$2tmmv$1@dont-email.me> References: <v2l828$18v7f$1@dont-email.me> <v38of2$1gsj2$1@dont-email.me> <v39v87$1n7bk$1@dont-email.me> <20240530170836.00005fa0@yahoo.com> <v3a3k5$1ntrn$1@dont-email.me> <20240530180345.00003d9f@yahoo.com> <v3chc4$27uij$1@dont-email.me> <20240531161937.000063af@yahoo.com> <20240531162811.00006719@yahoo.com> <20240531164835.00007128@yahoo.com> <v3cldt$28n91$2@dont-email.me> <20240531173437.00003bee@yahoo.com> <v3d3ct$2b5sl$1@dont-email.me> <yMo6O.3723$zfC8.2197@fx35.iad> <v3dem9$2d2v4$1@dont-email.me> <TLu6O.6222$xPJ1.816@fx09.iad> <v3essl$2nsh7$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sat, 01 Jun 2024 20:59:20 +0200 (CEST) Injection-Info: dont-email.me; posting-host="91ec5d79126354b953c01cb00293891d"; logging-data="3070687"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/BxQCtb2Fw1W05grRx9PEu" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:HZsniN557Elosrsw9TiRRa/6wcI= Content-Language: en-GB In-Reply-To: <v3essl$2nsh7$1@dont-email.me> Bytes: 4592 On 01/06/2024 11:24, bart wrote: > On 01/06/2024 02:25, Scott Lurndal wrote: [objcopy] > > Nope, same thing. This doesn't inspire much confidence. With values > shown, the actual size IS contained within the _size value, but only as > the last 16 bits of the value. > > gcc versions were 10.3.0 and 9.4.0 respectively; the latter is what is > provided by Windows 11. > > You also brought up the fact that the size is not known to the compiler > anyway, which means a few things are not possible, like using the size > in a static context. I thought I'd dash off my own version of 'objcopy' to see if I could do any better. This version does binary/text to COFF only. The input file here was a .wav file: C:\qapps>qq objcopy test.wav # running my objcopy Compiling test.m to test.obj Written test.obj # haven't settled on naming schemes yet char[] name is: test_wav u64 size name is: test_wav_len C:\qapps>gcc demo.c test.obj C:\qapps>a Size = 14355 Data = 52 49 46 ... The demo.c file is this: #include <stdio.h> extern char test_wav[]; extern long long test_wav_len; int main(void) { printf("Size = %lld\n", test_wav_len); printf("Data = %02x %02x %02x ...\n", test_wav[0], test_wav[1], test_wav[2]); } And this is info about the binary to show the right data has got into the C program: C:\qapps>dir test.wav 01/11/1996 04:05 14,354 test.wav C:\qapps>dump test.wav Dump of test.wav; Size = 14354 bytes 0000: 52 49 46 46 0A 38 00 00 57 41 56 45 66 6D 74 20 RIFF.8..WAVEfmt There is one slight discrepancy: the size from the C file is one byte bigger; that's because I'm using 'strinclude' (in the code compiled during the process, which adds a terminator. I can fix that easily, or allow the option. The script used to implement my 'objcopy' is shown below. It writes out a 2-line program which is compiled by my systems language into an object file. ------------------------------------------------ proc main= if ncmdparams<1 then println "Usage:" println " qq objcopy filename [name]" stop fi infile:=cmdparams[1] basename:=extractbasefile(infile) mfile:=basename+".m" objfile:=basename+".obj" if infile in (mfile, objfile) then abort("Name clash") fi name:=basename+"_"+extractext(infile) if ncmdparams>1 then name:=cmdparams[2] fi writetextfile(mfile, ( sfprint("export []byte # = strinclude(""#"")",name, infile), sfprint("export int #_len = #.len", name, name) ) ) if system("mm -obj "+mfile)<>0 then abort("Compile error on "+mfile) else println "Written", objfile println "char[] name is:",name println "u64 size name is:",name+"_len" fi end