Programming Languages on Power

Power Programming Languages

IBM Power, including the AIX, IBM i, and Linux operating systems, support a wide range of programming languages, catering to both traditional enterprise applications and modern development needs.


#Power


#Servers
#Programminglanguages
 View Only
  • 1.  CHAR_MIN value on Power 8

    Posted 06/30/17 08:45 AM

    Originally posted by: unrue


    Dear IBM developers, 

    I'm using xlc 13.1.5 on Power 8 system. I've noted that CHAR_MIN from limits.h is set to 0. 

    Under Intel machine otherwise is -128.

    I have a code with some cast from float to char. When the float is negative, under IBM the cast return 0 and the program doesn't works well. Is there any particolar reason of such difference?

    Is it possible to change CHAR_MIN value?

    Thanks. 


    #C/C++andFortran
    #Ask-Question-Here--General-Compiler-Q-and-A


  • 2.  Re: CHAR_MIN value on Power 8

    Posted 06/30/17 09:24 AM

    Originally posted by: Rafik_Zurob


    Hello

     

    In POSIX, the value of CHAR_MIN is tied to whether "char" is the signed or unsigned.  To make it -128, compile with -qchars=signed.  i.e. That would make "char" signed.  XLC's default is that "char" is unsigned.

    > cat x.c
    #include <limits.h>
    #include <stdio.h>
    
    int main() {
      printf("%d\n", (int) CHAR_MIN);
    }
    > xlc x.c
    > ./a.out
    0
    > xlc x.c -qchars=unsigned
    > ./a.out
    0
    > xlc x.c -qchars=signed
    > ./a.out
    -128
    >
    

    #C/C++andFortran
    #Ask-Question-Here--General-Compiler-Q-and-A


  • 3.  Re: CHAR_MIN value on Power 8

    Posted 07/05/17 02:07 PM

    Originally posted by: ThinkOpenly


    "-qchars=signed" ("-fsigned-char" for GCC) is a big lever to throw, which could have undesired effects in other code.

    It can be argued that since a "char" has an architecturally defined signedness, it is more appropriate to change the variable declarations to the match the desired behavior.  In other words, if the signedness of a char variable matters, declare that variable as "signed char" (or "unsigned char").  (I'm ignoring whether such changes are practical.)

    Note that limits.h defines, for "signed char" minimum value:

    #  define SCHAR_MIN     (-128)

     

    and then defines CHAR_MIN to that or 0, based on the architecture's default signedness for the "char" type.


    #C/C++andFortran
    #Ask-Question-Here--General-Compiler-Q-and-A