Path: csiph.com!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Effect of CPP tags Date: Thu, 04 Jan 2024 10:36:35 -0800 Organization: None to speak of Lines: 55 Message-ID: <87edext07g.fsf@nosuchdomain.example.com> References: <87o7e8voy1.fsf@nosuchdomain.example.com> <20231229122012.850@kylheku.com> <87il4at7pf.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: dont-email.me; posting-host="ffdb02b37e21d19b8cbab9b0b36b1681"; logging-data="3946183"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX195Fvnva8MlmQgjhS01l+72" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:hMlUOwsTxqQuNyTOGCiyzYeEuyo= sha1:rhsYK2HLA/OFbioB9NntAWqPRWE= Xref: csiph.com comp.lang.c:379837 David Brown writes: > On 03/01/2024 22:42, Keith Thompson wrote: >> David Brown writes: >>> On 02/01/2024 21:24, Bart wrote: >> [...] >>>> The X-macro solution was this, adapted from the first answer here >>>> (https://stackoverflow.com/questions/6635851/real-world-use-of-x-macros); assume those functions are in scope: >>>> ------- >>>> #define STATE_TABLE \ >>>>         ENTRY(STATE0, func0) \ >>>>         ENTRY(STATE1, func1) \ >>>>         ENTRY(STATE2, func2) \ >>>>         ENTRY(STATE3, func3) \ >>>> enum >>>> { >>>> #define ENTRY(a,b) a, >>>>     STATE_TABLE >>>> #undef ENTRY >>>>     NUM_STATES >>>> }; >>>> void* jumptable[NUM_STATES] = >>>> { >>>> #define ENTRY(a,b) b, >>>>     STATE_TABLE >>>> #undef ENTRY >>>> }; >>>> ------- >>> >>> (Why did you change the type from "p_func_t" to "void*" ? Was it just >>> to annoy myself and other C programmers with a pointless and >>> constraint-violating cast of a function pointer to "void*" ? Just add >>> a suitable typedef - "typedef void(*p_func_t)(void);" ) >> What constraint does it violate? And what cast are you referring >> to? > > I believe the initialisation follows the requirements for simple > assignment, and function pointers are not compatible with void*. Bart > (for reasons understood only by him) uses void* pointers when he wants > generic function pointers. The stack overflow link uses "p_func_t", > which is a function pointer typedef. Bart's code initializes array elements of type void* with values that are presumably of pointer-to-function type. That is indeed a constraint violation (one that, unfortunately, gcc doesn't even warn about with default options). David, your use of the word "cast" confused me. What's happening in the code is an implicit conversion, not a cast (or it would be if that particular implicit conversion were defined in the language, or if you're using a non-standard C dialect that defines it). -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for Medtronic void Void(void) { Void(); } /* The recursive call of the void */