Re: how to make it work

Liste des GroupesRevenir à cl c  
Sujet : Re: how to make it work
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.c
Date : 29. Aug 2024, 17: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/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Date Sujet#  Auteur
29 Aug 24 * how to make it work12fir
29 Aug 24 +* Re: how to make it work6Ben Bacarisse
29 Aug 24 i`* Re: how to make it work5fir
29 Aug 24 i +* Re: how to make it work2Ben Bacarisse
29 Aug 24 i i`- Re: how to make it work1fir
29 Aug 24 i `* Re: how to make it work2James Kuyper
29 Aug 24 i  `- Re: how to make it work1fir
29 Aug 24 +* Re: how to make it work2Kaz Kylheku
29 Aug 24 i`- Re: how to make it work1fir
29 Aug 24 `* Re: how to make it work3Bonita Montero
29 Aug 24  `* Re: how to make it work2fir
31 Aug 24   `- Re: how to make it work1Bonita Montero

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal