Problem with Initializing Consts
- by UdiM
This code, when compiled in xlC 8.0 (on AIX 6.1), 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