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,205 of 243,242   
   bart to Janis Papanagnou   
   Re: _BitInt(N)   
   28 Nov 25 11:49:40   
   
   From: bc@freeuk.com   
      
   On 28/11/2025 02:33, Janis Papanagnou wrote:   
   > On 11/27/25 18:59, bart wrote:   
   >> On 27/11/2025 17:38, Ike Naar wrote:   
   >>> On 2025-11-27, bart  wrote:   
   >>>> Well, let's stick with C. Here are some features I use, and the C   
   >>>> equivalents (A has whatever type is needed):   
   >>>>   
   >>>>      M                   C   
   >>>>      -------------------------------------------------------------   
   >>>> [snip]   
   >>>>      A.odd               A & 1, or A % 1   
   >>>   
   >>> "A % 1" ?   
   >>   
   >> I guess A % 2 then.   
   >   
   > You guess? - LOL - okay. :-)   
   >   
   >> Note my remark about error proneness later on.   
   >   
   > Higher level abstractions (usually found in higher level languages)   
   > are always less error prone than low-level (or composed) constructs.   
   >   
   > "C" is inherently and by design a comparably low-level language, so   
   > I wonder what you complain here about. (You won't change that.)   
      
   So is mine. But it has many more 'commodity' features that make life   
   simpler. Plus a generally cleaner syntax to make it clearer.   
      
      
   > 'even' and 'odd' are higher level abstractions than bit-operations,   
   > and they are also _special cases_ (nonetheless useful; I like them,   
   > and I appreciate if they are present in any language). The general   
   > case of the terms like "odd" and "even" is defined mathematically,   
   > though;   
      
   The advantage of using '.odd' is that the language doesn't specify how   
   it works, just the behaviour.   
      
   (But internally, 'A.odd' is an alias for 'A.[0]', and 'A.even' is one   
   for 'not A.[0]', but with the extra proviso that these are read-only:   
   while `A.[0] := x' is possible, you can't do 'A.odd := x'.)   
      
      
   > so the natural way of describing them would (IMO) rather be   
   > based on 'x mod 2 = 1' and 'x mod 2 = 0' respectively. (So the "C"   
   > syntax with '%' is probably more "appropriate". Mileages may vary.)   
      
   I've made the mistake with % 1 more than once.   
      
      
   > You can of course add as many commodity features to "your language"   
   > as you like. I seem to recall that one of the design principles of   
   > "C" was to not add too many keywords. (Not sure whether 'A.odd' is   
   > a function or keyword above [in "your language"].)   
      
   It is a reserved word, which means it can't be used as either a   
   top-level user identifier, or a member name. With extra effort, it could   
   be used for both, but that needs some special syntax, such as Ada-style   
   "A'odd"; I've never got around to it.   
      
   In Pascal (where I copied it from) it is a reserved word.   
      
   > You made a mistake above (or just a typo), never mind. I suppose it   
   > stems from your primary "thinking in bits". - This is not meant to   
   > be offensive. - Back in university days (I still remember!) I made   
   > a similar typo but vice versa; I wanted to express "div 2" in some   
   > assembler language and accidentally wrote "shift-right 2", the same   
   > type of typo but the other way round. I *knew*, and didn't "guess",   
   > though, that "shift-right 1" would have been correct. ;-)   
      
   I use a decimal type in another language. There bitwise operations don't   
   work. I would have to define what they might do. For example, the   
   possibilities for `123 << 2`  might be:   
      
     - Not valid (how it works now)   
     - 12300 (shift decimal digits)   
     - 492   (shift 'binary' digits)   
      
   That last simply defines as 'A << n' as meaning 'A * 2**n'.   
      
   > PS: BTW, I was always wondering why Pascal and Algol 68 supported   
   > 'odd' but not 'even'! - In the documents of the Genie compiler we   
   > can read: "This is a relic of times long past.", but beyond that   
   > it doesn't explain why it's a "relic". I can only guess that it's,   
   > as a special case, considered just unnecessary in the presence of   
   > the modulus operator.   
      
   Maybe because you can trivially define 'even' as 'not odd'.   
      
   --- 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