Path: csiph.com!news.dns-netz.com!news.freedyn.net!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: No, C is not a simple language Date: Tue, 11 May 2021 05:29:33 -0700 Organization: A noiseless patient Spider Lines: 53 Message-ID: <86zgx1fo7m.fsf@linuxsc.com> References: <878s5f1im9.fsf@nosuchdomain.example.com> <86h7k2h66j.fsf@linuxsc.com> <87tuo2yqiq.fsf@nosuchdomain.example.com> <2HofI.289439$hcZe.74935@fx46.ams4> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="ce98507e466523ba1e4f65ba30f9b784"; logging-data="9112"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ZiIzwsZGiXcsFWqetLbpdTWtRb6z5y0Y=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:0dCSg6qnKle+opelWw9nPGDndJY= sha1:39/05KjWI9qrhYCWREtTQC6dm/0= Xref: csiph.com comp.lang.c:160731 Bart writes: > On 19/04/2021 23:03, Richard Damon wrote: > >> On 4/19/21 4:21 PM, Keith Thompson wrote: >> >>> Thiago Adams writes: >>> >>>> [converting between object pointers and function pointers] >>> >>> C does not define the behavior of converting between object >>> pointer types and function pointer types (except for the special >>> case of a null pointer constant). I believe that's been the case >>> since C90. >>> >>> The section of the standard on pointer conversions just omits any >>> mention of conversions between object pointer types and function >>> pointer types. The section on cast operators, however, doesn't >>> say that such a conversion is a constraint violation. I find this >>> odd. (I think we had a long and inconclusive discussion about >>> this a while ago.) >>> >>> It does allow conversions of function pointer types to and from >>> integers, and integers to and from object pointer types, but the >>> results are implementation-defined in most cases. >>> >>> And yes, the rationale is that void* has to be big enough to hold >>> any object pointer value, but function pointers might be bigger >>> than object pointers (more precisely, they might not be >>> convertible without loss of information). >> >> It isn't made a constraint violation because in many cases it does >> work and being able to do it is useful. >> >> It isn't defined to work, because on some machines it just can't be >> done (especially if they are different sizes or to different memory >> spaces like a Harvard Machine) > > You can always make it work. On any machine where a raw function > pointer is very different from an object pointer (say 256 bits vs, > 64 bits), then a C compiler can implement such pointers via object > pointers. > > In practice, for every actual function, there is an accompanying > 256-bit value, in data memory, containing its address. A > 'function pointer' as a C program will see it, is a 64-bit pointer > to that 256-bit object. This idea isn't practical due to difficulties in managing the needed resource allocation. Furthermore it isn't necessary because there are easy ways around having to do such conversions.