Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #161816

Re: naked switches

From Bart <bc@freeuk.com>
Newsgroups comp.lang.c
Subject Re: naked switches
Date 2021-07-10 13:04 +0100
Organization A noiseless patient Spider
Message-ID <scc2cs$orb$1@dont-email.me> (permalink)
References (6 earlier) <20210708103653.702@kylheku.com> <9a999021-6733-4d00-91fb-9797570a1328n@googlegroups.com> <sc9190$h4g$1@dont-email.me> <sc9gav$iln$1@dont-email.me> <scc085$6h2$1@dont-email.me>

Show all headers | View raw


On 10/07/2021 12:28, David Brown wrote:
> On 09/07/2021 14:44, Bart wrote:

>> Then there would have been no need for the [] indexing syntax either.
>> You'd just write:
>>
>>    GETINDEX(a, i)
>>    SETINDEX(a, i, x)
>>
>> instead of a[i] or a[i]=x. Except these need special headers to be
>> dragged in, and everyone would be using their own incompatible macros;
>> try mixing code from different sources.
> 
> In a programming language, you want convenient syntax for things you do
> a lot, and you can happily have inconvenient syntax for things you only
> need to do occasionally.  (This works the other way too - you pick a
> language that has convenient syntax for the things you do often.  Or at
> least, that's what sensible programmers do.  Some people prefer to pick
> a language they don't like and complain instead.)
> 
> Accessing bit-fields like this is very rare - even in embedded
> programming, it is not something you do so much that existing C syntax
> is a problem.  Accessing arrays, however, is massively useful.


It's probably rare because the language doesn't support them! If 
available, they would be used a lot more. (As you've said, the macro to 
set the value of an arbitrary bitfield is not trivial.)

C does have bitfield indexing, but only for named fields in structs and 
with poor control over layout. Having it available for any integer value 
would be convenient.

I don't use bit/bitfield indexing that much, but the underlying 
mechanisms needed for that are used to implement my own, 
better-controlled version of C's struct bitfields.

And used to allow things like A.msb (as both lvalue and rvalue), and 
A.even/A.odd (rvalue only).

> 
>>
>>> You need very good reasons for
>>> adding non-portable extensions.
>>
>> Such a set of macros as you propose would also be non-portable unless
>> you included custom headers. And then you mix code that needs
>> BIT(a,10,1) with code that needs BIT(a,1,10).
> 
> Yes, but the great thing about headers with simple macros is that they
> are extremely portable.

Nothing is more portable than what is built-in to a language or to a 
standard library.

I keep coming across macros for min and max, or MIN and MAX, or ones to 
extract an array length without having to do that dance with sizeof this 
over sizeof that. All candidates for standardisation.

>>
>> You don't however seem to mind using GNU C extensions!
> 
> No, I don't - but I generally don't need my code to be portable beyond
> gcc and occasionally a few older embedded compilers.
> 
> There are two C and C++ toolchains that totally dominate - MSVC on
> Windows, and gcc on everything else.  The next most popular toolchains
> are clang then probably icc, both of which support a fair number of gcc
> extensions.
> 
> So a gcc extension is likely to be portable to perhaps 90% of all
> non-Windows C or C++ development work.  That's more than good enough for
> my needs.
> 
> An extension in /your/ tool, or Robert Finch's tool, is portable to
> perhaps 0.0000000001% of C or C++ development work.  That is rather
> different.

The ideas would be portable to 99% of C implementations if they prove 
viable and useful (remember my 'strinclude' feature). Where do you think 
most gcc extensions came from?

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

naked switches Robert Finch <robfi680@gmail.com> - 2021-07-07 16:39 -0700
  Re: naked switches Bart <bc@freeuk.com> - 2021-07-08 01:26 +0100
  Re: naked switches Kaz Kylheku <563-365-8930@kylheku.com> - 2021-07-08 01:57 +0000
    Re: naked switches David Brown <david.brown@hesbynett.no> - 2021-07-08 09:16 +0200
  Re: naked switches Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-07-08 01:00 -0700
    Re: naked switches Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2021-07-08 03:25 -0700
      Re: naked switches Robert Finch <robfi680@gmail.com> - 2021-07-08 06:58 -0700
        Re: naked switches Bart <bc@freeuk.com> - 2021-07-08 15:52 +0100
        Re: naked switches David Brown <david.brown@hesbynett.no> - 2021-07-08 17:52 +0200
          Re: naked switches Bart <bc@freeuk.com> - 2021-07-08 17:51 +0100
            Re: naked switches David Brown <david.brown@hesbynett.no> - 2021-07-09 10:01 +0200
              Re: naked switches Bart <bc@freeuk.com> - 2021-07-09 11:09 +0100
                Re: naked switches David Brown <david.brown@hesbynett.no> - 2021-07-09 13:14 +0200
                Re: naked switches Manfred <noname@add.invalid> - 2021-07-09 15:35 +0200
                Re: naked switches David Brown <david.brown@hesbynett.no> - 2021-07-09 16:51 +0200
                Re: naked switches Manfred <noname@add.invalid> - 2021-07-09 18:23 +0200
                Re: naked switches Bart <bc@freeuk.com> - 2021-07-09 16:07 +0100
                Re: naked switches Manfred <noname@add.invalid> - 2021-07-09 18:41 +0200
                Re: naked switches David Brown <david.brown@hesbynett.no> - 2021-07-10 11:02 +0200
                Re: naked switches David Brown <david.brown@hesbynett.no> - 2021-07-09 19:20 +0200
                Re: naked switches Robert Finch <robfi680@gmail.com> - 2021-07-09 10:46 -0700
                Re: naked switches Kaz Kylheku <563-365-8930@kylheku.com> - 2021-07-09 19:56 +0000
                Re: naked switches Bart <bc@freeuk.com> - 2021-07-09 22:01 +0100
                Re: naked switches Robert Finch <robfi680@gmail.com> - 2021-07-09 15:07 -0700
                Re: naked switches Bart <bc@freeuk.com> - 2021-07-09 23:30 +0100
                Re: naked switches David Brown <david.brown@hesbynett.no> - 2021-07-10 12:17 +0200
          Re: naked switches Robert Finch <robfi680@gmail.com> - 2021-07-08 10:18 -0700
            Re: naked switches Bart <bc@freeuk.com> - 2021-07-08 18:43 +0100
              Re: naked switches Robert Finch <robfi680@gmail.com> - 2021-07-08 15:32 -0700
            Re: naked switches Kaz Kylheku <563-365-8930@kylheku.com> - 2021-07-08 17:47 +0000
              Re: naked switches Robert Finch <robfi680@gmail.com> - 2021-07-08 15:45 -0700
                Re: naked switches David Brown <david.brown@hesbynett.no> - 2021-07-09 10:27 +0200
                Re: naked switches Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-07-09 11:13 +0100
                Re: naked switches David Brown <david.brown@hesbynett.no> - 2021-07-09 13:30 +0200
                Re: naked switches Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-07-11 00:39 -0700
                Re: naked switches scott@slp53.sl.home (Scott Lurndal) - 2021-07-11 14:06 +0000
                Re: naked switches Robert Finch <robfi680@gmail.com> - 2021-07-11 08:01 -0700
                Re: naked switches Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-07-16 03:53 -0700
                Re: naked switches scott@slp53.sl.home (Scott Lurndal) - 2021-07-16 14:47 +0000
                Re: naked switches Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-09-30 06:09 -0700
                Re: naked switches Robert Finch <robfi680@gmail.com> - 2021-09-30 07:03 -0700
                Re: naked switches Bart <bc@freeuk.com> - 2021-07-09 13:44 +0100
                Re: naked switches David Brown <david.brown@hesbynett.no> - 2021-07-10 13:28 +0200
                Re: naked switches Bart <bc@freeuk.com> - 2021-07-10 13:04 +0100
                Re: naked switches David Brown <david.brown@hesbynett.no> - 2021-07-10 15:39 +0200
                Re: naked switches Bart <bc@freeuk.com> - 2021-07-10 15:08 +0100
                Re: naked switches David Brown <david.brown@hesbynett.no> - 2021-07-10 17:34 +0200
                Re: naked switches Bart <bc@freeuk.com> - 2021-07-10 17:47 +0100
              Re: naked switches Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-07-11 00:57 -0700
                Re: naked switches Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-07-16 03:51 -0700
        Re: naked switches Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-07-08 11:40 -0700
          Re: naked switches David Brown <david.brown@hesbynett.no> - 2021-07-09 10:38 +0200
  Re: naked switches Kaz Kylheku <563-365-8930@kylheku.com> - 2021-07-08 17:33 +0000
    Re: naked switches scott@slp53.sl.home (Scott Lurndal) - 2021-07-08 17:47 +0000
      Re: naked switches Kaz Kylheku <563-365-8930@kylheku.com> - 2021-07-08 17:58 +0000
        Re: naked switches scott@slp53.sl.home (Scott Lurndal) - 2021-07-08 19:13 +0000
          Re: naked switches Kaz Kylheku <563-365-8930@kylheku.com> - 2021-07-09 02:30 +0000
        Re: naked switches David Brown <david.brown@hesbynett.no> - 2021-07-09 10:41 +0200
  Re: naked switches Bonita Montero <Bonita.Montero@gmail.com> - 2021-09-30 18:04 +0200

csiph-web