返回int main的代码-是否有上限?
Return codes for int main - is there a cap?
我今天一直在使用返回代码,为此我在bash中创建了一个for循环来进行测试:
for RC in {1..300}
do
echo "int main(void) { return $RC; }" > test.cpp
g++ test.cpp -o test
./test
echo $?
done
然而,在达到255之后,它似乎又从0开始。为什么呢?
,
252
253
254
255
0
1
因为在posix兼容的系统中返回码被限制在[0-255]范围内。
关于Bash,这里有一个关于退出状态的方便参考。
相关文章:
- 是否可以从int转换为enum类类型
- '[](std::list& list)<int>{return std::move(list)}(list)' 是否保证将 'list' 留空?
- 是否可以保证按字节的零 int 是零的表示形式?
- 是否可以将无符号 int 的最大值转换为 int 并将结果转换为 -1?
- 是否需要动态分配单个 int?
- 如何检查 int 变量是否包含合法(非陷阱表示)值?
- 检查类是否具有模板专用化(使用布尔值或 int 等模板参数)
- 如何检查字符串是否正确以将其转换为 int?
- 检查字符串是否是数字,然后将该数字转换为 int?
- 如何检查 int 中是否恰好设置了一位?
- 是否应该避免这种从 int 到双精度的静态转换?
- 是否打印指向已定义 int 的成员指针
- unordered_set是否适合存储矢量<int>元素的数据结构?如果是这样,我将如何实现哈希函数?
- 是否有可能在没有复制的情况下传递 std::vector<int> 作为参数来获得 std::vector<std::array<int, 3>>?
- 是否可以交换在 c++ 中作为函数 func(say) 中的参数传递的 const 向量的两个元素,例如:vector<int>func (const vector<int>&
- Windows.h Sleep(int) 函数是否浪费?
- 将uint8_t转换为已签名的 int 是否至少有时不正确?
- 涡轮增压 这个声明“int fun-name(static int)”在C++中是否有效,为什么
- 数据类型是否"int"定义为类?
- 新分配的 std::vector 元素是否<int>初始化为 0?