Deutsch English Français Italiano |
<v3f2f3$2oq04$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: jak <nospam@please.ty> Newsgroups: comp.lang.c Subject: Re: C23 thoughts and opinions Date: Sat, 1 Jun 2024 13:59:32 +0200 Organization: A noiseless patient Spider Lines: 99 Message-ID: <v3f2f3$2oq04$1@dont-email.me> References: <v2l828$18v7f$1@dont-email.me> <v3758s$14hfp$1@raubtier-asyl.eternal-september.org> <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> <v3du01$2fej5$1@dont-email.me> <v3es0l$2nkse$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Sat, 01 Jun 2024 13:59:32 +0200 (CEST) Injection-Info: dont-email.me; posting-host="728b09861fb379a3c088593349670a89"; logging-data="2910212"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19x5FQELRTkl/OnrlDCxWaM" User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0 SeaMonkey/2.53.18.2 Cancel-Lock: sha1:F3EyfffpJohDtOOs71iMbhQUXOk= In-Reply-To: <v3es0l$2nkse$1@dont-email.me> Bytes: 4730 bart ha scritto: > On 01/06/2024 02:37, jak wrote: >> bart ha scritto: >>> I can see that the first two can be subtracted to give the sizes of >>> the data, which is 70 or 0x46. 0x46 is the last byte of the address >>> of _size, so what's happening there? What's with the crap in bits 16-47? >>> >>> I can extract the size using: >>> >>> printf("%d\n", (unsigned short)&_binary_hello_c_size); >>> >>> But something is not right. I've also asked what is the point of the >>> -size symbol if you can just do -end - -start, but nobody has explained. >> >> typedef unsigned char uchar; >> extern uchar _binary_hello_c_size[]; >> long hello_c_size = _binary_hello_c_size - (uchar *)0; > > What result for the size did you get when you ran this? > > It seems people are just guessing what might be the right code and > posting random fragments! > I wrote it that way precisely because I believed it was the clearest way. With the extern you can retrive the relative values that in the case of _start and _end correspond to the initial and final address of the object, in fact you can get the length of the object by subtracting the starting address from the final one: extern char _binary_hello_c_start[]; extern char _binary_hello_c_end[]; long len = _binary_hello_c_end - _binary_hello_c_start; Unfortunately, _size is provided in the same way as _start and _end addresses, then, since it is not an address but a length and in C: Address +/- Value = Address Address +/- Address = Value so, to retrive this length that in the program it is seen as an address it is sufficient to subtract the starting address which in the case of a length is zero. extern char _binary_hello_c_size[]; long len = _binary_hello_c_size - (char *)0; surely you can also recover the value with a cast: long len = (long)_binary_hello_c_size; but the example I sent you had seemed more explanatory while the cast seems to me a blow of hoe. Here nobody invents anything. I'm sorry you think this. /* * example: * file to embed: * --- start file.txt --- * line number 1 * line number 2 * line number 3 * line number 4 * line number 5 * line number 6 * line number 7 * line number 8 * line number 9 * line number 10 * line number 11 * line number 12 * line number 13 * line number 14 * line number 15 * line number 16 * line number 17 * line number 18 * line number 19 * line number 20 * --- end file.txt --- * objcopy --input-target binary --output-target pe-x86-64 --binary-architecture i386 file.txt file.txt.o * gcc embed.c file.txt.o -o embed */ #include <stdio.h> int main() { typedef unsigned char uchar; extern uchar _binary_file_txt_start[]; extern uchar _binary_file_txt_size[]; long file_txt_size = _binary_file_txt_size - (uchar *)0; for(long i = 0; i < file_txt_size; i++) putchar(_binary_file_txt_start[i]); return 0; } output: show file.txt content