Software > Applications and Porting

Problem with std::numeric_limits<char>::max()

(1/1)

DKnoto:
I'm porting my software to ppc64le and ran into a problem in the std::numeric_limits<char>::max() function. According to
the documentation, this operation should return the value CHAR_MAX which is 127. This is the case on x86_64 with gcc 11.3.1
compiler. Unfortunately on ppc64le the code compiled with gcc 12.2.1 returns the value UCHAR_MAX which is 255.

Test code:

--- Code: ---printf("std::numeric_limits<char>::max() == %d\n", static_cast<int>(std::numeric_limits<char>::max()));

--- End code ---

Clang 14.0.5 and IBM xlc 16.01.0001.0003 return the same value.

Have any of you encountered such a problem on distributions other than Fedora 36?

 

DKnoto:
On FreeBSD 14.0 ppc64 with clang 14.0.5 has the same thing.

adunsmuir:
The data type char maps to either signed char or unsigned char depending on the platform.
It is not a fixed part of the C++ (or C) standards.

Is there any conditional logic in the headers that is getting miss-triggered in gcc 12?  What does gcc 13 do?

Al Dunsmuir

DKnoto:
I checked it out at https://en.cppreference.com/w/cpp/types/climits. Actually in the example it says that these are "possible values". Nevertheless, I am very surprised that C++ defines its portability so poorly.

The same algorithm implemented in Java works equally on both platforms.

The test code:


--- Code: ---import java.lang.*;

public class JLimits
{
    public static void main(String[] args)
    {
        System.out.printf("byte.MAX_VALUE == %d.\n", Byte.MAX_VALUE);
    }
}

--- End code ---

Thanks for the hint, I am implementing a workaround.

DKnoto:
The workaround is trivial:

--- Code: ---typedef signed char byte;

--- End code ---

 ;)

Navigation

[0] Message Index

Go to full version