c++ - 初始化常量的问题

标签 c++ aix xlc

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

错误在哪里?

#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 工作正常,似乎是一个编译器错误

关于c++ - 初始化常量的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2645383/

相关文章:

linux - ftp 命令中的 Tab 按钮

linux - 向每列添加多个值

c++ - 如何通过编译器命令行禁用 IBM xl C++ 编译器的特定警告?

c++ - XLC++ 11.1 的奇怪问题

c - 参数类型对此链接类型的函数无效

c++ - 使用 .def 或 __declspec(dllexport) 导出跨平台代码的共享库符号?

c++ - 警告:std::binary_function<int, int, bool>::binary_function() 在静态库 "*.a"中具有不同的可见性(默认)

c++ - Stock incoming char in 循环函数

c - AIX 运行时错误 : Symbol __dbargs (number 191) is not exported from dependent

c++ - 获取 ASM 中特定地址寄存器的值