NO

Author Topic: CHAR  (Read 6160 times)

Offline John Z

  • Member
  • *
  • Posts: 860
CHAR
« on: November 04, 2023, 01:04:03 PM »
In both 32 bit and 64 bit compiling some mini zip code I ran across this warning message:
C:\Program Files\PellesC\Files\.....\Zip\miniz.h(4117): warning #2074: Escape sequence '\xae' is out of range for 'char'.
C:\Program Files\PellesC\Files\.....\Zip\miniz.h(4117): warning #2074: Escape sequence '\x82' is out of range for 'char'.

But 'char' storage is one byte which should go to \xff so it seems it is checking for char < 127

Is it a valid warning?

John Z

Offline MrBcx

  • Global Moderator
  • Member
  • *****
  • Posts: 189
    • Bcx Basic to C/C++ Translator
Re: CHAR
« Reply #1 on: November 04, 2023, 02:34:03 PM »
Possible cause:

CHAR is signed char
BYTE is unsigned char

https://learn.microsoft.com/en-us/windows/win32/winprog/windows-data-types

Bcx Basic to C/C++ Translator
https://www.BcxBasicCoders.com

Offline John Z

  • Member
  • *
  • Posts: 860
Re: CHAR
« Reply #2 on: November 04, 2023, 03:31:45 PM »
Thanks MrBCX,

Makes sense if CHAR is signed.  Looks like signed CHAR is somewhat implementation specific.
Std on x86(mostly), unsigned on ARM generally and changeable with an option.
After your hint I found:
Quote
"Is char type is signed by default in C?
By default, char behaves like an unsigned char . To change this default, you can use the DFTCHAR(*SIGNED|*UNSIGNED) option or the #pragma chars directive. See DFTCHAR(*SIGNED|*UNSIGNED) in the ILE C/C++ Compiler Reference for more information.

Character types - IBM
ibm.com

Thanks - with this looks like not a mistake warning.

John Z

Offline MrBcx

  • Global Moderator
  • Member
  • *****
  • Posts: 189
    • Bcx Basic to C/C++ Translator
Re: CHAR
« Reply #3 on: November 05, 2023, 12:58:50 AM »
Robert Wishlaw shared this tip/trick a couple years ago:

Here is a one liner to check the compiler's default signedness for the char data type.

printf("%d\n",'\x80');


-128 means default is signed char

128 means default is unsigned char

Default for Nuwen, MSVC, CLang and Pelles C is signed.

To change MSVC and Pelles C to unsigned char default add

/J

flag to command line.

To change Nuwen and CLang to unsigned char default add

-funsigned-char

flag to command line.
Bcx Basic to C/C++ Translator
https://www.BcxBasicCoders.com

Offline Robert

  • Member
  • *
  • Posts: 247
Re: CHAR
« Reply #4 on: November 05, 2023, 08:20:33 PM »
Robert Wishlaw shared this tip/trick a couple years ago:

Here is a one liner to check the compiler's default signedness for the char data type.

printf("%d\n",'\x80');


-128 means default is signed char

128 means default is unsigned char

Default for Nuwen, MSVC, CLang and Pelles C is signed.

To change MSVC and Pelles C to unsigned char default add

/J

flag to command line.

To change Nuwen and CLang to unsigned char default add

-funsigned-char

flag to command line.

As well as the above, additional information is in the Remarks section of the BCX Documentation for char at

https://bcxbasiccoders.com/webhelp/html/variables.htm#char

Offline WiiLF23

  • Member
  • *
  • Posts: 89
Re: CHAR
« Reply #5 on: January 06, 2024, 08:15:07 PM »
You will also encounter these warnings using cJSON library (github).

In same cases, casting a primitive type resolves "possible lost of data" like use INT_PTR blah = SendMessage(...) which you must read by casting (int) so it removes the warnings. I resolved 4 sections of my code nagging about this.