C compiler flag to ignore sign

I am currently working on code purchased from a third-party contractor. One structure has an unsigned char field, and the function to which they pass this field requires a signed char. The compiler does not like this because it considers them to be inappropriate types. However, it seems to be compiling for this contractor. Some Googling told me that "[i] t is determined by the implementation whether the char object can contain negative values." Can a contractor compiler ignore a signed / unsigned type and treat them the same? Or is there a compiler flag that will handle them the same way?

C is not my strongest language - just look at my tags on my user page - so any help would be greatly appreciated.

+3
source share
3 answers

In fact char, signed charand unsigned charare three different types. From the standard (ISO / IEC 9899: 1990):

6.1.2.5 Types

...

The three types are char , signed char and unsigned char are collectively called character types.

(and in C ++, for example, you should (or at least should) write override functions with three variants of them, if you have a char argument)

A regular char can be handled by a signed or unsigned compiler, but the standard says (also in 6.1.2.5):

, char, . 5.2.1 char, . char, : .

, , char, , '' plain '' char.

, 5.2.1, A-Z, a-z, 0-9, , , 29 :

! " # % & ' ( ) * + , - . / :
; < = > ? [ \ ] ^ _ { | } ~ 

, , , ascii 128 . , , , 128, ( ), .

+3

. , V++ _CHAR_UNSIGNED, unsigned char.

+1

, signed char unsigned char, . char, , (IIRC, , char - signed unsigned), . - .

Alternatively, the contractor may use the compiler or compiler options that allow it to compile while ignoring errors or warnings. Do you know what his compilation environment is?

In any case, this is not good. If one of the types is simple char, it relies on the behavior defined by the implementation and therefore is not portable. If not, then this is wrong. I will take this with the contractor.

0
source

Source: https://habr.com/ru/post/1716590/


All Articles