在xlC 8.0(在AIX 5.3上)中编译时,此代码产生错误的结果。
它应该打印12345,但是打印804399880
删除const前面的result可使代码正常工作。

错误在哪里?

#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;
}

编译命令:
/usr/vacpp/bin/xlC example.cpp -g

编辑:将上面的printf格式字符串更改为“%ld \ n”无济于事。
编辑2:使用的AIX版本是5.3,而不是6.1。

最佳答案

xlC 10.0正常运行,似乎是编译器错误

09-10 00:09
查看更多