Path: ...!news.nobody.at!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Kaz Kylheku <643-408-1753@kylheku.com> Newsgroups: comp.lang.c Subject: Re: how to make it work Date: Thu, 29 Aug 2024 15:22:31 -0000 (UTC) Organization: A noiseless patient Spider Lines: 49 Message-ID: <20240829081259.348@kylheku.com> References: <877194bd8a95b9acb03db317ee000e94cce2834d@i2pn2.org> Injection-Date: Thu, 29 Aug 2024 17:22:31 +0200 (CEST) Injection-Info: dont-email.me; posting-host="ee676becc5cc43d653dc7d1580a96201"; logging-data="32033"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/3ym4pD9f2UvPpNSHfwH0eUinwrTGeb+4=" User-Agent: slrn/pre1.0.4-9 (Linux) Cancel-Lock: sha1:Gsw1bzUaSB1nJMK7OLZWpUea+E0= Bytes: 2429 On 2024-08-29, fir wrote: > see such code > > > long long unsigned tag ; > > void foo(long long unsigned tag) > { > if(tag=='warsaw') printf("\nwarsaw"); > if(tag=='paris') printf("\nparis"); > if(tag=='new york') printf("\nnew york"); > if(tag=='old york') printf("\nold york"); #define EIGHTCC(A, B, C, D, E, F, G, H) \ ((uint64_t) (A) << 56 | \ (uint64_t) (B) << 48 | \ (uint64_t) (C) << 40 | \ (uint64_t) (D) << 32 | \ (uint64_t) (E) << 24 | \ (uint64_t) (F) << 16 | \ (uint64_t) (G) << 8 | \ (uint64_t) (H)) #define WARSAW EIGHTCC(' ', 'w', 'a', 'r', 's', 'a', 'w') #define PARIS EIGHTCC(' ', ' ', 'p', 'a', 'r', 'i', 's') > if(tag=='very old york') printf("\nvery old york"); This one won't fit; it has 13 characters. The EIGHTCC macro requires exactly eight arguments, so you won't define anything like this by accident. The binary code coul use an abbreviation, while the constant symbol has a longer name: #define VERY_OLD_YORK EIGHTCC('v', 'o', 'l', 'd', 'y', 'r', 'k') If you care about easily reading these strings in memory dumps, you can adjust the calculation in EIGHTCC according to the endianness of the machine. I have it the wrong way around for the predominant little endian; we want to go from H to A. -- TXR Programming Language: http://nongnu.org/txr Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal Mastodon: @Kazinator@mstdn.ca