Deutsch English Français Italiano |
<v6gl83$s72a$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: James Kuyper <jameskuyper@alumni.caltech.edu> Newsgroups: comp.lang.c Subject: =?UTF-8?Q?Re=3A_technology_discussion_=E2=86=92_does_the_world_need?= =?UTF-8?B?IGEgIm5ldyIgQyA/?= Date: Mon, 8 Jul 2024 00:28:53 -0400 Organization: A noiseless patient Spider Lines: 43 Message-ID: <v6gl83$s72a$1@dont-email.me> References: <v66eci$2qeee$1@dont-email.me> <v67gt1$2vq6a$2@dont-email.me> <v687h2$36i6p$1@dont-email.me> <871q48w98e.fsf@nosuchdomain.example.com> <v68dsm$37sg2$1@dont-email.me> <87wmlzvfqp.fsf@nosuchdomain.example.com> <v6ard1$3ngh6$4@dont-email.me> <v6b0jv$3nnt6$1@dont-email.me> <87h6d2uox5.fsf@nosuchdomain.example.com> <v6d779$6rk5$2@dont-email.me> <v6e76u$c0i9$1@dont-email.me> <v6esqm$fian$2@dont-email.me> <v6f7vg$hgam$1@dont-email.me> <20240707164747.258@kylheku.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Injection-Date: Mon, 08 Jul 2024 14:14:59 +0200 (CEST) Injection-Info: dont-email.me; posting-host="82ac0bc5ac8679abf13c09bba0ac1135"; logging-data="924746"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/twOqZQORdMjH9Tk8Gk0CG2sBgs6QRuKM=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:oFEDkhWup8SCFD7UCVXUQgxYORE= In-Reply-To: <20240707164747.258@kylheku.com> Content-Language: en-US Bytes: 3245 On 7/7/24 20:02, Kaz Kylheku wrote: .... > Ritchie's B language had arrays which contained a pointer to their > first element. Via a hack, it was possible to relocate an array. > > In C, such a thing is not simply not required; it is ruled out > by the detailed semantic description of arrays. > > The entire representation of an array of size N elements of type > T is contained in the memory block that is sizeo(T)*N bytes wide. > > If you copy that block, you have a fully functional copy of the array. > No extra pointer needs to be set up with the correct value. An implementation which took the following code: int array1[5], array2[5]; memcpy(array2, array1, sizeof array1); and translated it into machine code that was the equivalent of int array1[5], array2[5]; int *_p1 = &array1[0], *_p2 = &array2[0]; memcpy(_p2, _p1, sizeof array1); would not violate any of the requirements you mention. The key point is that when you copy the contents of an array to a new location, you wouldn't want to copy the implicit pointer - it would point at the wrong location. And if the destination is itself declared as an array, it would already have an implicit pointer that pointed at the correct location. I see no point in having implicit pointers, but I don't believe that they are prohibited. > Furthermore, to dynamically allocate an array, you need only > provide sizeof(T)*N bytes of storage, and not a bit more. > > There is simply nowhere in the representation of an array where > a pointer could hide that is part of the representation. Allocated memory is already accessed through a pointer; there would be no corresponding need to create an implicit one when there's already an explicit one.