2021年4月10日星期六

Defining a string as char* vs unsigned char*

I am using the pcre2 library, and it has a special 'string-type' defined as PCRE2_SPTR8.

If I try and initialize a string with something like:

PCRE2_SPTR8 s =   "my string";  

I'll get a warning such as:

warning: initializing 'PCRE2_SPTR8' (aka 'const unsigned char *')            with an expression of type 'char [27]' converts between pointers to           integer types with different sign [-Wpointer-sign]  

What would be the suggested way to initialize this type of string? Doing something like:

PCRE2_SPTR8 s =   (PCRE2_SPTR8) "my string";  

Additionally, out of curiosity why is a normal "string" usually defined as char* string = "something"; instead of unsigned char* string = "something";. Is there any advantage/disadvantage of defining a string with a signed vs. unsigned char?

https://stackoverflow.com/questions/67040648/defining-a-string-as-char-vs-unsigned-char April 11, 2021 at 09:17AM

没有评论:

发表评论