Path: csiph.com!weretis.net!feeder8.news.weretis.net!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Beginner....Decimal/Octal converter help Date: Tue, 13 Sep 2022 11:48:48 -0700 Organization: None to speak of Lines: 43 Message-ID: <87a673hzzj.fsf@nosuchdomain.example.com> References: <8ffd982c-2e82-4caa-9256-ec17be2efe56n@googlegroups.com> <86leqsr091.fsf@linuxsc.com> <875yhv30nu.fsf@bsb.me.uk> <87zgf714zc.fsf@bsb.me.uk> <8735cy0wt4.fsf@bsb.me.uk> <87r10hzn19.fsf@bsb.me.uk> <87mtb4wq4f.fsf@bsb.me.uk> <875yhswfiv.fsf@bsb.me.uk> MIME-Version: 1.0 Content-Type: text/plain Injection-Info: reader01.eternal-september.org; posting-host="86c5ac014cfaf5e873242a1911ff41a4"; logging-data="2786538"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18EQV/hTTrPIOeBddFPg3xI" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:elTOfgU/Xg8teI0luWCKlYXostw= sha1:VskatqC+RloL+CL1ds5lmbq8Kl4= Xref: csiph.com comp.lang.c:167679 David Brown writes: [...] > While thinking about newer C features, I have found another challenge > with using multiple different sometimes incompatible aliases for > integer types - _Generic. I don't know if you've used _Generic much, > but it can sometimes be useful. Here is a small example : > > #include > #include > #include > > #define print_var(_x) \ > do { \ > printf("Var " # _x " = "); \ > printf( \ > _Generic(_x, \ > uint8_t : "0x%02" PRIx8, \ > uint16_t : "0x%04" PRIx16, \ > uint32_t : "0x%08" PRIx32, \ > uint64_t : "0x%016" PRIx64), \ > _x); \ > printf("\n"); \ > } while (0); I'd use the predefined types unsigned char, unsigned short, et al rather than the uintN_t types. For example, if uint32_t is unsigned int and uint64_t is unsigned long long, then passing an unsigned long argument is an error. Using the predefined types guarantees that you'll cover all the integer types. You can use sizeof to determine the number of digits. Except that it all breaks down if some of the types in are defined as extended integer types. There's no good way for a _Generic expression to cover all the integer types if the implementation supports extended integer types. (Then again, I'm not aware of any implementations that do so.) [...] -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for Philips void Void(void) { Void(); } /* The recursive call of the void */