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


Groups > comp.lang.c > #75790

Re: memset extensions

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: memset extensions
Date 2015-11-11 13:19 -0800
Organization None to speak of
Message-ID <lnsi4cqlmo.fsf@kst-u.example.com> (permalink)
References (2 earlier) <n1vqhm$u0o$2@dont-email.me> <87lha4ladh.fsf@bsb.me.uk> <n207p4$o0l$2@dont-email.me> <5643AC9B.2030305@verizon.net> <n20aav$3rt$1@dont-email.me>

Show all headers | View raw


jacobnavia <jacob@jacob.remcomp.fr> writes:
> Le 11/11/2015 22:01, James Kuyper a écrit :
> I wrote
>>> This is done in the lexical analysis phase.
>
>> True. But it's not a promotion.
>
> Exactly. That is why _Generic will not work, as I stated in my message.

That's only a problem if the argument is a character constant -- and if
it is, then you're probably going to use memset() anyway.

For your extended memset*() functions, if they're implemented as a macro
using _Generic, then the argument can be either an object of the
expected type:

    const uint16_t value = 0xabcd;
    new_memset(addr, value, count);

or a cast can be used to guarantee that _Generic unambiguously sees
the type you want it to:

    new_memset(addr, (uint16_t)0xabcd, count);

I'm not suggesting that _Generic is the best way to implement this, just
that type promotion is not a barrier to doing so.

On the other hand, the substantially different behavior depending on the
type of the argument could cause some confusion.  Programmers are likely
to expect an argument to be implicitly converted to the parameter type.
Giving it an all-caps name to make it clear that it's a macro and
clearly documenting the behavior might avoid most of that confusion.

I *think* that separate functions are still a better way to do this.

You might even want to have functions for each of the uintN_t types
*and* for the predefined unsigned types.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

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


Thread

memset extensions jacobnavia <jacob@jacob.remcomp.fr> - 2015-11-11 11:05 +0100
  Re: memset extensions Lőrinczy Zsigmond <zsiga@nospam.for.me> - 2015-11-11 11:08 +0100
    Re: memset extensions "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-11 04:56 -0800
  Re: memset extensions Philipp Klaus Krause <pkk@spth.de> - 2015-11-11 13:39 +0100
    Re: memset extensions jacobnavia <jacob@jacob.remcomp.fr> - 2015-11-11 17:34 +0100
      Re: memset extensions Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-11 17:22 +0000
        Re: memset extensions jacobnavia <jacob@jacob.remcomp.fr> - 2015-11-11 21:19 +0100
          Re: memset extensions Keith Thompson <kst-u@mib.org> - 2015-11-11 12:51 -0800
          Re: memset extensions James Kuyper <jameskuyper@verizon.net> - 2015-11-11 16:01 -0500
            Re: memset extensions jacobnavia <jacob@jacob.remcomp.fr> - 2015-11-11 22:03 +0100
              Re: memset extensions Keith Thompson <kst-u@mib.org> - 2015-11-11 13:19 -0800
                Re: memset extensions jacobnavia <jacob@jacob.remcomp.fr> - 2015-11-11 22:45 +0100
                Re: memset extensions James Kuyper <jameskuyper@verizon.net> - 2015-11-11 16:51 -0500
                Re: memset extensions jacobnavia <jacob@jacob.remcomp.fr> - 2015-11-11 23:01 +0100
                Re: memset extensions James Kuyper <jameskuyper@verizon.net> - 2015-11-11 17:29 -0500
                Re: memset extensions jacobnavia <jacob@jacob.remcomp.fr> - 2015-11-11 23:36 +0100
                Re: memset extensions Keith Thompson <kst-u@mib.org> - 2015-11-11 15:00 -0800
              Re: memset extensions James Kuyper <jameskuyper@verizon.net> - 2015-11-11 16:48 -0500
          Re: memset extensions Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-11 22:15 +0000
  Re: memset extensions James Kuyper <jameskuyper@verizon.net> - 2015-11-11 08:05 -0500
  Re: memset extensions Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-11-11 08:31 -0500
    Re: memset extensions jacobnavia <jacob@jacob.remcomp.fr> - 2015-11-11 17:34 +0100
  Re: memset extensions Les Cargill <lcargill99@comcast.com> - 2015-11-11 08:30 -0600
    Re: memset extensions Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-11-11 09:48 -0500
    Re: memset extensions gwowen <gwowen@gmail.com> - 2015-11-11 07:55 -0800
    Re: memset extensions James Kuyper <jameskuyper@verizon.net> - 2015-11-11 11:24 -0500
    Re: memset extensions jacobnavia <jacob@jacob.remcomp.fr> - 2015-11-11 17:32 +0100
      Re: memset extensions Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-11-11 11:44 -0500
      Re: memset extensions raltbos@xs4all.nl (Richard Bos) - 2015-11-17 22:53 +0000
        Re: memset extensions supercat@casperkitty.com - 2015-11-17 15:37 -0800
          Re: memset extensions raltbos@xs4all.nl (Richard Bos) - 2015-11-20 11:27 +0000
            Re: memset extensions supercat@casperkitty.com - 2015-11-20 08:45 -0800
  Re: memset extensions supercat@casperkitty.com - 2015-11-11 08:25 -0800
  Re: memset extensions Keith Thompson <kst-u@mib.org> - 2015-11-11 09:09 -0800
    Re: memset extensions supercat@casperkitty.com - 2015-11-11 09:18 -0800
      Re: memset extensions Keith Thompson <kst-u@mib.org> - 2015-11-11 10:57 -0800
    Re: memset extensions jacobnavia <jacob@jacob.remcomp.fr> - 2015-11-11 21:17 +0100

csiph-web