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在哪里?
#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
", result);
}
int
main()
{
bar();
return 0;
}
汇编指挥:
/usr/vacpp/bin/xlC example.cpp -g
Edit: Changing the printf format string above to "%ld " doesn t help. Edit 2: The AIX version used was 5.3, not 6.1.