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


Groups > comp.lang.c > #150931

Re: Portable way of reading str[4] as uint32_t

From Spiros Bousbouras <spibou@gmail.com>
Newsgroups comp.lang.c
Subject Re: Portable way of reading str[4] as uint32_t
References <40d1f926-8737-4332-93f2-c37c46f731f9@googlegroups.com> <yOvgG.106450$Gy2.9178@fx30.iad> <5a25b5b4-bd49-4a4a-a64b-3799a000b7f9@googlegroups.com> <nOBSUi8oUySOmiMBwD@bongo-ra.co> <affbf457-551a-41c0-819c-16e36adb136b@googlegroups.com>
Message-ID <ILBTaDTYdPVqRGZ6wQ6@bongo-ra.co> (permalink)
Organization virginmedia.com
Date 2020-03-31 18:03 +0000

Show all headers | View raw


On Tue, 31 Mar 2020 09:59:03 -0700 (PDT)
wyniijj@gmail.com wrote:
> Spiros Bousbouras於 2020年3月31日星期二 UTC+8下午7時29分19秒寫道:
> > On Mon, 30 Mar 2020 23:28:33 -0700 (PDT)
> > wyniijj@gmail.com wrote:
> > > What is actually stored in str[4] is one utf8 character, unused bytes are 
> > > filled with zeros. I'd like to access it faster, as uint32_t.
> > 
> > How was the UTF-8 character stored there ? Can you show us some example code
> > which does the storing ? What do you want to do with it when accessing it
> > as  uint32_t ? The code you have in your opening post is one way to do the
> > accessing but whether it's useful for what further processing you need to
> > do , I don't know.

> No real code yet.

Still , you must have some idea how the UTF-8 (representation of a)
character will be stored in the array. For example the UTF-8 sequence
for  A  has 1 element with the value 65. What will the contents of
uint8_t[4]  be for this ? The UTF-8 sequence for  於  has 3 elements which
are  230 150 188 .What will the contents of uint8_t[4]  be for this ?

> I'm designing a struct like
> 
> struct SNode {
>   struct SNode *m_parent;
>   int m_xtype;      // the real type of m_xptr
>   void *m_xptr;
> };
> 
> where m_xptr might store an utf8 character if m_xtype says so.
> If so, this 'uint32_t' value may be passed among many functions.

But you still need to specify what correspondence you want between the UTF-8
representation and the  uint32_t  value. Based on what you say below , I'm
guessing that you want to get the unicode codepoint from the UTF-8 represen-
tation but I'm not sure. You also need to specify whether the  uint8_t[4]
array will be guaranteed to have a valid UTF-8 sequence or whether you want
your code to also check for that.

> some function might check its uint32_t argument being less than 128(or more) and
> can use it as an array index. Therefore, I need a consistent way that convert
> uint8_t[4] to uint32_t and latin1 characters is required to convert to equal value.
> 
> > I note also that to have  uint32_t  you need
> > #include <stdint.h>

-- 
vlaho.ninja/prog

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


Thread

Protable way of reading str[4] as uint32_t wyniijj@gmail.com - 2020-03-30 11:42 -0700
  Re: Protable way of reading str[4] as uint32_t Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-03-30 20:14 +0100
    Re: Protable way of reading str[4] as uint32_t Jorgen Grahn <grahn+nntp@snipabacken.se> - 2020-03-30 20:11 +0000
  Re: Protable way of reading str[4] as uint32_t Richard Damon <Richard@Damon-Family.org> - 2020-03-30 20:04 -0400
    Re: Protable way of reading str[4] as uint32_t Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-03-30 19:04 -0700
      Re: Protable way of reading str[4] as uint32_t wyniijj@gmail.com - 2020-03-30 23:30 -0700
        Re: Protable way of reading str[4] as uint32_t Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-03-31 10:59 -0700
          Re: Protable way of reading str[4] as uint32_t Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-03-31 12:19 -0700
            Re: Protable way of reading str[4] as uint32_t wyniijj@gmail.com - 2020-04-01 06:37 -0700
    Re: Protable way of reading str[4] as uint32_t wyniijj@gmail.com - 2020-03-30 23:28 -0700
      Re: Portable way of reading str[4] as uint32_t Spiros Bousbouras <spibou@gmail.com> - 2020-03-31 11:29 +0000
        Re: Portable way of reading str[4] as uint32_t wyniijj@gmail.com - 2020-03-31 09:59 -0700
          Re: Portable way of reading str[4] as uint32_t Spiros Bousbouras <spibou@gmail.com> - 2020-03-31 18:03 +0000
        Re: Portable way of reading str[4] as uint32_t Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-04-02 19:09 -0700
          Re: Portable way of reading str[4] as uint32_t Spiros Bousbouras <spibou@gmail.com> - 2020-04-03 05:02 +0000
            Re: Portable way of reading str[4] as uint32_t James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-04-03 01:10 -0400
              Re: Portable way of reading str[4] as uint32_t gazelle@shell.xmission.com (Kenny McCormack) - 2020-04-03 08:18 +0000
              Re: Portable way of reading str[4] as uint32_t Spiros Bousbouras <spibou@gmail.com> - 2020-04-03 09:48 +0000
                Re: Portable way of reading str[4] as uint32_t gazelle@shell.xmission.com (Kenny McCormack) - 2020-04-03 11:07 +0000
            Re: Portable way of reading str[4] as uint32_t BGB <cr88192@gmail.com> - 2020-04-03 09:41 -0500
              Re: Portable way of reading str[4] as uint32_t Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-03 07:51 -0700
                Re: Portable way of reading str[4] as uint32_t Richard Damon <Richard@Damon-Family.org> - 2020-04-03 12:09 -0400
                Re: Portable way of reading str[4] as uint32_t BGB <cr88192@gmail.com> - 2020-04-03 13:19 -0500
                Re: Portable way of reading str[4] as uint32_t James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-04-03 14:52 -0400
                Re: Portable way of reading str[4] as uint32_t Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-04-03 12:10 -0700
                Re: Portable way of reading str[4] as uint32_t BGB <cr88192@gmail.com> - 2020-04-03 15:17 -0500
                Re: Portable way of reading str[4] as uint32_t James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-04-03 23:39 -0400
                Re: Portable way of reading str[4] as uint32_t Spiros Bousbouras <spibou@gmail.com> - 2020-04-03 21:28 +0000
            Re: Portable way of reading str[4] as uint32_t Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-04-04 19:28 -0700
      Re: Protable way of reading str[4] as uint32_t Richard Damon <Richard@Damon-Family.org> - 2020-03-31 08:05 -0400
        Re: Protable way of reading str[4] as uint32_t BGB <cr88192@gmail.com> - 2020-03-31 09:12 -0500
          Re: Protable way of reading str[4] as uint32_t Philipp Klaus Krause <pkk@spth.de> - 2020-03-31 17:27 +0200
            Re: Protable way of reading str[4] as uint32_t BGB <cr88192@gmail.com> - 2020-03-31 18:26 -0500
              Re: Protable way of reading str[4] as uint32_t Jorgen Grahn <grahn+nntp@snipabacken.se> - 2020-04-01 06:03 +0000
                Re: Protable way of reading str[4] as uint32_t Richard Damon <Richard@Damon-Family.org> - 2020-04-01 08:17 -0400
                Re: Protable way of reading str[4] as uint32_t James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-04-01 09:57 -0400
                Re: Protable way of reading str[4] as uint32_t BGB <cr88192@gmail.com> - 2020-04-01 09:47 -0500
                Re: Protable way of reading str[4] as uint32_t James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-04-01 11:48 -0400
                Re: Protable way of reading str[4] as uint32_t BGB <cr88192@gmail.com> - 2020-04-01 12:37 -0500
      Re: Protable way of reading str[4] as uint32_t James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-03-31 12:56 -0400

csiph-web