This code, when compiled in xlC 8.0 (on AIX 5.3), produces the wrong result.
It should print 12345, but instead prints 804399880.
Removing the const in front of result makes the code work correctly.
Where is the bug?
#include <stdio.h>
#include <stdlib.h>
#include <string>
long int foo(std::string input)
{
return strtol(input.c_str(), NULL, 0);
}
void bar()
{
const long int result = foo("12345");
printf("%u\n", result);
}
int
main()
{
bar();
return 0;
}
Compilation command:
/usr/vacpp/bin/xlC example.cpp -g
Edit: Changing the printf format string above to “%ld\n” doesn’t help.
Edit 2: The AIX version used was 5.3, not 6.1.
xlC 10.0 works fine, seems to be a compiler bug