Raptor Computing Systems Community Forums (BETA)
Software => Applications and Porting => Topic started by: DKnoto on November 03, 2022, 02:37:51 pm
-
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:
printf("std::numeric_limits<char>::max() == %d\n", static_cast<int>(std::numeric_limits<char>::max()));
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?
-
On FreeBSD 14.0 ppc64 with clang 14.0.5 has the same thing.
-
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
-
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:
import java.lang.*;
public class JLimits
{
public static void main(String[] args)
{
System.out.printf("byte.MAX_VALUE == %d.\n", Byte.MAX_VALUE);
}
}
Thanks for the hint, I am implementing a workaround.
-
The workaround is trivial:
typedef signed char byte;
;)