Sujet : Re: how to make it work
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.cDate : 29. Aug 2024, 16:22:31
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240829081259.348@kylheku.com>
References : 1
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2024-08-29, fir <
fir@grunge.pl> 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/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca