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


Groups > comp.lang.c > #75792

Re: memset extensions

From James Kuyper <jameskuyper@verizon.net>
Newsgroups comp.lang.c
Subject Re: memset extensions
Date 2015-11-11 16:48 -0500
Organization Self
Message-ID <5643B7BC.6090307@verizon.net> (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


On 11/11/2015 04:03 PM, jacobnavia wrote:
> 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.

In the previous message where you used the word "promoted", you gave the
supposed occurence of a promotion as a reason why _Generic couldn't be used:

> _Generic can't be used since
> 
> 'A' --> integer
> 120 --> integer also
> 
> You would never get a value less than int since all others are promoted 
> automatically

_Generic() can recognize types smaller than int (which, I presume, is
what you meant by "get a value less than int"), because promotions don't
occur in the argument of a _Generic() association.

#define Memset(dest, value, count) _Generic(value, \
    uint16_t: _memset16( (dest), (value), (count)),      \
    uint32_t: _memset32( (dest), (value), (count)),      \
    uint64_t: _memset64( (dest), (value), (count)),      \
    uint128_t:_memset128((dest), (value), (count))       \
    default: /* Error handling */)

All of the following cases should be correctly handled by Memset(),
assuming I wrote this correctly (this is untested code, and therefore
likely to contain errors):

    uint16_t ui16 = 12345;
    uint32_t ui32 = 1234567890;
    uint64_t ui64 = 12345678901234567890;
    uint128_t ui128 =
        123456789012345678901234567890123456789;
    uint16_t  array16[128];
    uint32_t  array32[ 64];
    uint64_t  array64[ 32];
    uint128_t array128[16];

    Memset(array16,  ui16, 128);
    Memset(array32,  ui32,  64);
    Memset(array64,  ui64,  32);
    Memset(array128, ui128, 16);

These, on the other hand, won't work:

    char c = 'A';
    // will trigger default: because the argument type is 'char'
    Memset(array16, c, 256);

   // will trigger default: because argument type is 'int'
    Memset(array16, 'A', 256);

However, that shouldn't matter, because with those values you probably
should be calling memset() rather than Memset().

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