Re: how to make it work

Liste des GroupesRevenir à l c 
Sujet : Re: how to make it work
De : fir (at) *nospam* grunge.pl (fir)
Groupes : comp.lang.c
Date : 29. Aug 2024, 18:24:32
Autres entêtes
Organisation : i2pn2 (i2pn.org)
Message-ID : <1992be9d4f2e5fb5994946cbce08531b9ed5a6ee@i2pn2.org>
References : 1 2
User-Agent : Mozilla/5.0 (Windows NT 5.1; rv:27.0) Gecko/20100101 Firefox/27.0 SeaMonkey/2.24
Kaz Kylheku wrote:
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.
>
>
this is bad i need it strictly for simplicity and convenience
as the goal is to get rid enums which are shit becouse it spread code and makes terrible code jumping - makin real pain in the head if you write bigger program with an increasing dose of enums
in fact instead of macro (i dont use macros) i could
just write a normal function which takes string up to 8
asci and generates unsigned64 from it then
sorta lieke
u64 convert(char^ tag)
{
   u64 value = (u64)tag[0] + (u64)tag[1]*256 + (u64)tag[2]*256*256 +
(u64)tag[3]*256*256*256 + (u64)tag[4]*256*256*256*256 + ....
  returbn value;
}
and as it will be passed with constant char* = "new york" ;
i could hope that in compile time those calls would be just
optimised to 65 bit values on assembly level
but will it do?
enums are overally shit and they are almost unusable and some alternative needs to be used

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