Path: csiph.com!aioe.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Why does C allow structs to have a tag? Date: Fri, 11 Jun 2021 15:28:55 -0700 Organization: None to speak of Lines: 44 Message-ID: <87im2kyr14.fsf@nosuchdomain.example.com> References: <1bzgw0tpqu.fsf@pfeifferfamily.net> <45b9fa5f-d715-451c-b236-1a5d236614f7n@googlegroups.com> <20210609104104.187@kylheku.com> <20210609135620.66@kylheku.com> <87wnr0z0o8.fsf@nosuchdomain.example.com> <20210611124436.183@kylheku.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: reader02.eternal-september.org; posting-host="b3dc605b3c3d09671336ab6840e77b5e"; logging-data="30101"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+89ZPxyD3vJhbDw7Qm4W32" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:nb8ojKLvJPak4/yxZftSRe/bWQc= sha1:LGV/E4B4aclBHAZ3/8Ud6g2YmGE= Xref: csiph.com comp.lang.c:161389 Kaz Kylheku <563-365-8930@kylheku.com> writes: > On 2021-06-11, Guillaume wrote: >> Le 11/06/2021 à 21:00, Keith Thompson a écrit : >>> Bart writes: >>> [...] >>>> What's wrong with it? How would /you/ turn a function pointer into a >>>> void* type? >>> >>> Most likely I wouldn't. >> >> According to C99, a pointer to a function is compatible with a pointer >> to a function of a different type. Compatibility with a pointer to any >> other object is not defined indeed. That can suggest, for instance, that >> pointers to functions may have a different size than others pointers, >> making a conversion impossible on some platforms. > > Those platforms wouldn't have a GetProcAddress or dlopen function, > which means they are either specialized DSPs running very specialized, > single-purpose firmware, very tiny microcontrollers also running > very specialized firmware, or else museum machines. dlopen (defined by POSIX, not by C) return a void* that's a handle to a dynamic library. You can pass that handle, along with a pointer to a string to dlsym() to get the address of an object or function. POSIX requires that a void* value *returned by dlsym()* can be converted to the appropriate function pointer type and used to call the function. As far as I can tell, it imposes no such requirement for pointer conversions in general (I think that might be a relatively recent change in POSIX). An implementation where, for example, function pointers are bigger than void* could still support dlsym() with some special case code. (It's very likely that there are no actual implementations that need to do this.) I'm less familiar with GetProcAddress (a Windows thing), but it returns a result of type FARPROC, which apparently is actually defined as a function pointer type. There are probably no Windows implementations where function pointers are bigger than object pointers, but GetProcAddress isn't what prevents that. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for Philips Healthcare void Void(void) { Void(); } /* The recursive call of the void */