Am 27.04.2020 um 04:21 schrieb Paul Gilmartin:
On Mon, 27 Apr 2020 03:49:00 +0200, Bernd Oppolzer wrote:

First of all, char in C is a subtype of int,
which means that you can do normal arithmetic operations to chars
and that chars are allowed in int expressions without special action
needed.

for example:

char c;

c = 'A' + 1;   /* c will be 'B' */
c = c - 'A' + 'a'; /* c will now be 'b' - lower case */

Agreed.  Yet no such compatibility exists among unsigned char *,
signed char *, and char*.  However, many implementations quietly
ignore violations of this.  I encountered this on IBM mainframe when
a FOSS program attempted to call a (standard, such as strlen()?)
function expecting a char * argument with an unsigned char *.

The intrinsic type of "XYZ" here is char *, not unsigned char *, and
surely not signed char *.

Yes,

the compiler flags functions calls where unsigned char * arguments (for example) are passed to char * parameters, even if the default signage for char is unsigned - usually a warning. There is in fact no difference between the types on z/OS (given the unsigned default), but there would be a difference when compiled on other platforms. The compiler issues the warning anyway. Of course, you can ignore such warnings.

AFAIK, the ANSI functions like strlen, strcmp etc. have char * parameters (no signage specified), so the problem arises if you pass unsigned char pointers or arrays to them. The problem IMO would also occur, if you would pass explicitly signed char pointers or arrays.

You can get rid of the warnings by casting your arguments:

x = strlen ((char *) my_unsigned_string);

OTOH, if you write own functions which must process a passed string as a string of
unsigned chars, you cass pass it as char * and cast it inside, that is:

int myfunc (char *str)

{
   unsigned char *ustr = (unsigned char *) str;
   /* now work with ustr instead of str */
   ...
}

HTH, kind regards

Bernd

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

Reply via email to