Deutsch English Français Italiano |
<v6oct4$2djgq$2@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: David Brown <david.brown@hesbynett.no> Newsgroups: comp.lang.c Subject: =?UTF-8?Q?Re=3A_technology_discussion_=E2=86=92_does_the_world_need?= =?UTF-8?B?IGEgIm5ldyIgQyA/?= Date: Thu, 11 Jul 2024 12:41:40 +0200 Organization: A noiseless patient Spider Lines: 77 Message-ID: <v6oct4$2djgq$2@dont-email.me> References: <v66eci$2qeee$1@dont-email.me> <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> <v6gl83$s72a$1@dont-email.me> <v6h8ao$ur1v$1@dont-email.me> <v6jhk3$1drd6$1@dont-email.me> <v6jiud$1dsjb$1@dont-email.me> <877cdur1z9.fsf@bsb.me.uk> <v6joi4$1epoj$1@dont-email.me> <871q42qy33.fsf@bsb.me.uk> <v6k6i0$1h4d3$1@dont-email.me> <87ed82p28y.fsf@bsb.me.uk> <v6m03l$1tf05$1@dont-email.me> <87r0c1nzjj.fsf@bsb.me.uk> <v6m716$1urj4$1@dont-email.me> <87ikxconq4.fsf@bsb.me.uk> <v6n8iu$24af0$1@dont-email.me> <20240711115418.00001cdf@yahoo.com> <v6oamt$2d8nn$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Thu, 11 Jul 2024 12:41:41 +0200 (CEST) Injection-Info: dont-email.me; posting-host="ae48152f062f08333130ccb39a825b01"; logging-data="2543130"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/M/HTtDh/XcbuUQGeRC6B8PqVMOocl7W8=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:glbs2CWKtPgyEy11xGwltXwre1Y= Content-Language: en-GB In-Reply-To: <v6oamt$2d8nn$1@dont-email.me> Bytes: 4900 On 11/07/2024 12:04, bart wrote: > On 11/07/2024 09:54, Michael S wrote: >> No, it isn't. >> If [in C] it was possible to pass arrays to functions, either by value >> or by reference, then callee would know the length of passed array. As >> it is, callee does not know it. > >> The length can be passed in a separate parameter, but then it does not >> have to be the same as an original. > > That's rather specious. In my language (probably in C too), most passed > arrays are unbounded, allowing the same function to work with arrays of > different sizes. > > So that would need a separate Length parameter, even using by-reference. No. Like any object, an array has data, and characteristics including the type of the elements, and for an array, the length of the array. If you pass an object, by reference or by value, the receiver (function parameter, or caller if we are talking about return values) gets the characteristics as well as the data. In C, if you write code that looks a bit like it is passing an array, the object's characteristics don't follow along with it - therefore you are not passing the array. If in your language, the characteristics also do not follow, as part of the parameter, then your language cannot pass arrays either. If you need to have a separate manual length parameter, then your language is doing the same as C - you are passing a pointer by value without the full object information. So perhaps your confusion here lies in a misunderstanding of how arrays as passed in your own language, and you have carried that confusion over to C. > > In that regard, it's no different from the C: my array by-ref and C's > alledged by-ref both cannot determine the array length solely from the > parameter. > > (In my language, attempts to get the length yields 0, which makes sense > as the parameter's bounds are zero. In C, it will yield the size of the > pointer.) > > But when the array IS bounded, then in C: > > typedef byte vector[4]; > > void F(vector a) { > printf("%zu\n", sizeof(a)); > printf("%zu\n", sizeof(vector)); > } > > The first printf shows 8 (the pointer size); the second shows 4 (the > array size). So it /can/ access the bounds. No, it cannot access the bounds of the "array parameter" here. (I use quotation marks because there are no array parameters in C - just things that look a little like them.) F takes a pointer to byte as a parameter, not a "vector" or an array of bytes or a pointer to an array. The function has no more access to the size of a "vector" than it has access to the size of a "float". > > (For unbounded arrays, my language offers an alternative: slices, which > contain their length. This is available whatever the calling mechanism.) > A slice is presumably an object that encapsulates a pointer to data and size information - a struct. It might give a nice syntax in your language, but it is a different concept entirely.