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


Groups > comp.lang.c++ > #70784

Re: Question on a C++ string

From T <T@invalid.invalid>
Newsgroups comp.lang.c++
Subject Re: Question on a C++ string
Date 2019-12-29 12:10 -0800
Organization A noiseless patient Spider
Message-ID <qub171$dni$1@dont-email.me> (permalink)
References <qu9hgc$nut$1@dont-email.me> <h9kh0f1iv1gkovhcg7bk10e0u405pqk7dm@4ax.com>

Show all headers | View raw


On 2019-12-29 08:39, Barry Schwarz wrote:
> On Sat, 28 Dec 2019 22:35:54 -0800, T <T@invalid.invalid> wrote:
> 
>> Hi All,
>>
>> I have four different way of converting a Raku/Perl6 string
>> into a C++ string to pass to native call.  Three come out
> 
> The word string has two defined meanings in the C++ language.  One is
> the name of a type (std::string) defined in the Standard Template
> Library.  The other is an array of characters terminated by a 0 value
> as defined in the C standard which is included in C++ by reference.
> Which one do you mean?
> 
> What does "native call" mean?  Is it to a C (or C++) function?  What
> does that function expect?  Show us the prototype of the function.

Hi Barry,

Native Call is a module (documented by Satin himself)
in Raku/Perl6 that allows you to make system calls to .so
and .dll's.

> 
>> the same and one comes out with a 0x0000 (hex) at the end.
> 
> No they did not.  The last three are significantly different from each
> other.
> 
>> The "say" functions shows me each byte in the converted
>> string.  Which one is correct?
> 
> No, say did not show you that.  It showed you its interpretation of
> the argument you gave it.  At the very least, it did not show you
> seven bytes of data in the uint16 array.

Which was what I was after.

> Furthermore, none of the results is a std::string and only one of the
> results is a C-style string.

Native call converts this to a C string for you.  It is
not documented very well.


>> The following is "abcdefg" converted to a C string,
>> "wstr", etc. is the method I used and is not part
>> of the C string:
> 
> Something appears to be missing from this sentence.  What is the
> method you used?  And what is not part of what?
> 
>> 97 98 99 100 101 102 103       wstr
>> 97 98 99 100 101 102 103 0     to-c-str
> 
> This is a valid C-style string consisting of eight bytes/characters.
> 
>> 97 98 99 100 101 102 103       CArray[uint8].new
> 
> This is an array of seven bytes/integers that may be considered
> characters but it is not a string.
> 
>> 97 98 99 100 101 102 103       CArray[uint16].new
> 
> This is an array of fourteen bytes (seven integers) that may be
> considered wide characters but it is not a string.
> 
>> And why do I care if I am using "uint8" or "uint16"
>> to convert visable text?  What about the one
> 
> You care because the function you are calling may expect one or the
> other (or possibly have code to let it determine which you provided
> but that is unlikely).

Native Call adds the chr(0) to the end for you.  This
I had to find out through experimentation.

> 
>> with the 0 at the end?
> 
> This is the only one that is a string.  Whether that matters depends
> on the function you are calling.
> 

Since "W" calls use uint16, I settled on
     my $M = CArray[uint16].new("abcdefg".encode.list);
for simplicity.

Thank you for the wonderful help!  On my journey, I hit
a few curbs, ran over a fire hydrant, hit a squirrel
(that "might" have been on purpose, I ain't saying) but
I got there eventually!

-T

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


Thread

Question on a C++ string T <T@invalid.invalid> - 2019-12-28 22:35 -0800
  Re: Question on a C++ string Jorgen Grahn <grahn+nntp@snipabacken.se> - 2019-12-29 09:33 +0000
    Re: Question on a C++ string Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2019-12-29 01:45 -0800
      Re: Question on a C++ string T <T@invalid.invalid> - 2019-12-29 01:49 -0800
        Re: Question on a C++ string Jorgen Grahn <grahn+nntp@snipabacken.se> - 2019-12-29 11:04 +0000
        Re: Question on a C++ string Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2019-12-29 13:57 -0800
          Re: Question on a C++ string T <T@invalid.invalid> - 2019-12-29 14:57 -0800
    Re: Question on a C++ string T <T@invalid.invalid> - 2019-12-29 01:50 -0800
      Re: Question on a C++ string Jorgen Grahn <grahn+nntp@snipabacken.se> - 2019-12-29 11:08 +0000
        Re: Question on a C++ string T <T@invalid.invalid> - 2019-12-29 11:50 -0800
          Re: Question on a C++ string Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2019-12-29 13:57 -0800
            Re: Question on a C++ string T <T@invalid.invalid> - 2019-12-29 15:00 -0800
      Re: Question on a C++ string Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2019-12-29 13:57 -0800
        Re: Question on a C++ string T <T@invalid.invalid> - 2019-12-29 15:02 -0800
          Re: Question on a C++ string Paavo Helde <myfirstname@osa.pri.ee> - 2019-12-30 01:28 +0200
      Re: Question on a C++ string Sam <sam@email-scan.com> - 2019-12-29 21:47 -0500
  Re: Question on a C++ string Bo Persson <bo@bo-persson.se> - 2019-12-29 11:00 +0100
    Re: Question on a C++ string T <T@invalid.invalid> - 2019-12-29 02:33 -0800
      Re: Question on a C++ string Bart <bc@freeuk.com> - 2019-12-29 12:09 +0000
        Re: Question on a C++ string T <T@invalid.invalid> - 2019-12-29 11:51 -0800
  Re: Question on a C++ string Paavo Helde <myfirstname@osa.pri.ee> - 2019-12-29 12:17 +0200
    Re: Question on a C++ string Barry Schwarz <schwarzb@delq.com> - 2019-12-29 08:45 -0800
      Re: Question on a C++ string T <T@invalid.invalid> - 2019-12-29 11:54 -0800
  Re: Question on a C++ string Öö Tiib <ootiib@hot.ee> - 2019-12-29 02:56 -0800
    Re: Question on a C++ string T <T@invalid.invalid> - 2019-12-29 12:02 -0800
  Re: Question on a C++ string Barry Schwarz <schwarzb@delq.com> - 2019-12-29 08:39 -0800
    Re: Question on a C++ string T <T@invalid.invalid> - 2019-12-29 12:10 -0800

csiph-web