home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c      Meh, in C you gotta define EVERYTHING      243,242 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 242,270 of 243,242   
   Waldek Hebisch to David Brown   
   Re: _BitInt(N)   
   30 Nov 25 15:50:25   
   
   From: antispam@fricas.org   
      
   David Brown  wrote:   
   > On 29/11/2025 20:36, Waldek Hebisch wrote:   
   >> David Brown  wrote:   
   >   
   >>> _BitInt's are not arrays, they are scalars - they are integer types.   
   >>> There is no concept of a type "_BitInt" - they always have compile-time   
   >>> fixed sizes, such as "_BitInt(12)".  So the idea of passing around   
   >>> generic _BitInt's makes no more sense than passing around any other kind   
   >>> of generic integer types.  (Of course you can have an array of _BitInt's   
   >>> of any given size.)   
   >>   
   >> There are languages which pass generic types, but C is not one   
   >> of them.  So idea of passing around generic _BitInt's makes sense,   
   >> but this is not included in C.   
   >>   
   >   
   > By "pass around generic types", do you mean that you can write a   
   > function that handles different types in the same parameter spot, and   
   > have the function do different things for different passed-in types?  C   
   > has at least three ways to handle such things :   
   >   
   > 1. Variadic functions and the  macros.  "printf" is a prime   
   > example of a function that can take parameters of many different types.   
   >   
   > 2. Passing arbitrary data via "void *" pointers.  People do it all the time.   
   >   
   > 3. _Generic macros.  These are not functions, but can pass off control   
   > to different type-specific functions depending on the type of the arguments.   
   >   
   >   
   > You can use any of these methods with _BitInts, but they are all missing   
   > something significant in comparison to the support you would (and I   
   > expect will) get in C++ with a template-based std::bit_int, or in   
   > higher level languages like Python (if it had an equivalent of a set of   
   > _BitInt types).   
   >   
   > I therefore expect to be able to do more interesting things with _BitInt   
   > types in C++ than in C, and do so in much simpler ways than equivalents   
   > in C.   
   >   
   > My point was that to do "something with generic _BitInt's" you have to   
   > have to deal with a range of types, not one type with a range of sizes   
   > or bit-counts.   
      
   In case of _BitInt the relevant thing are parametrized types, especially   
   Extended Pascal schema types.  Typically each tuple of parameters   
   creates a new type, distinct from types created using different   
   tuples.  That may sound like C++ templates, but unlike templates   
   in Pascal types are logically created at runtime.  That is there   
   is no need to specify all needed possibilities at compile time.   
   And unlike languages with reference semantics in Pascal such   
   types can be passed by value and parameters may affect size of   
   the type.   
      
   There are languages where parametrized types have more capabilities   
   than in Pascal, but Pascal is IMO good example as it is otherwise   
   reasonably comparable to C.   
      
   --   
                                 Waldek Hebisch   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca