- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
考虑以下基本示例:
#include <stdio.h>
int main(void)
{
printf("Hi there!\n");
}
它会调用 C89 中的未定义行为吗?我试图从 this question 中获得一些意义,但大多数赞成的答案声称它是实现定义的,这里绝对没有 UB(Keith Thompson 的评论,这看起来很矛盾)。
规范在 §3.16 定义和约定中说:
If a “shall” or “shall not” requirement that appears outside of a constraint is violated. the behavior is undefined. Undefined behavior is otherwise indicated in this International Standard by the words “undefined behavior” or by the omission of any explicit definition of behavior. There is no difference in emphasis among these three: they all describe “behavior that is undefined”.
和 §5.1.2.2.3 程序终止:
A return from the initial call to the
main
function is equivalent to calling theexit
function with the value returned by themain
function as its argument. If themain
function executes a return that specifies no value, the termination status returned to the host environment is undefined.
我的理解是后面的子条款不包括缺少返回的情况,因为 return
语句不是从不调用的,因此适用前面的子条款。
然而,进一步阅读表明有些不同,§6.6.6.4 return
语句:
If a
return
statement without an expression is executed, and the value of the function call is used by the caller, the behavior is undefined. Reaching the}
that terminates a function is equivalent to executing areturn
statement without an expression.
好的,现在 5.1.2.2.3
子条款适用:
If the
main
function executes a return that specifies no value. the termination status returned to the host environment is undefined.
术语“终止状态未定义”似乎不是 UB,也不是任何特定行为,但更像是它超出了 C 标准的范围,更像是:“让宿主环境不用担心,我们从这里洗手”。是否正确解读?
最佳答案
几年前,我实际上调试了由此引起的问题。如果您有一些代码路径有返回值而其他代码路径没有返回值,它会变得更加有趣。
正如@aruisdante 在评论中推测的那样,表现出的行为确实是“未定义”的,但唯一未定义的部分是返回值(它不像许多其他可能导致程序崩溃的“未定义”情况)。
现在这实际上构成了安全风险,因为返回的“未定义”值通常是通常用于返回值的 CPU 寄存器中(或在某些实现中的堆栈中)的任何内容,理论上可用于泄露敏感数据。
关于c - 是否省略了 C89(又名 ANSI C)中的 return 语句未定义行为?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28203506/
我正在寻找一个控制代码来使用 ANSI 或其他一些标准在终端中创建橙色文本,这可能吗?我只看到黄色和红色可用,我认为您不能将红色和黄色混合用于同一个角色:) 最佳答案 严格来说,不:ANSI 从未标准
我知道 \33[nC移动光标 n列向前;问题是,我不知道特定行包含多少个字符。 最佳答案 什么都没有显式 ,但是屏幕“小”,您可以使用任何光标移动命令移动到任意远的目的地,终端将通过屏幕大小限制移动。
这个问题在这里已经有了答案: Oracle Joins - Comparison between conventional syntax VS ANSI Syntax (11 个回答) 8 年前关闭。
我知道在 bash 终端中,一种可靠的变色方法是使用 ANSI 转义序列。例如: echo -e "\033[0;31mbrown text\033[0;00m" 应该输出 brown text (i
上次我检查时,说您正在使用 ANSI C 编码等同于说“这是符合 C99 的代码,其中没有任何其他内容”。现在有了 C11 和 C++11,这种区别还存在吗?它还有某种意义吗? 最佳答案 历史上,“A
我的业务逻辑包含在大约 7000 行 T-SQL 存储过程中,其中大多数都具有下一个 JOIN 语法: SELECT A.A, B.B, C.C FROM aaa AS A, bbb AS B, cc
我的业务逻辑包含在大约 7000 行 T-SQL 存储过程中,其中大多数都具有下一个 JOIN 语法: SELECT A.A, B.B, C.C FROM aaa AS A, bbb AS B, cc
我正在使用 CentOS 7 和 PHP 7.0 TERM=xterm-256color 我确实有一个彩色提示和 ls 颜色,如果我通过 --ansi然后它确实显示为彩色,但我不想总是添加 --ans
在我工作过的每家公司,我发现人们仍然按照 ANSI-89 标准编写 SQL 查询: select a.id, b.id, b.address_1 from person a, address b wh
我正在使用 Delphi RIO 10.3.3。 当我将 Ansi 字符串作为 const 数组的元素之一传递时,string() 转换对其不起作用。为了让它工作,我必须先将 VAnsiString
我正在使用 Delphi RIO 10.3.3。 当我将 Ansi 字符串作为 const 数组的元素之一传递时,string() 转换对其不起作用。为了让它工作,我必须先将 VAnsiString
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
当我在终端上调整大小时,它保持全屏显示。我想,有某种方法可以找出终端的屏幕尺寸。我怎样才能在 VT100 中做到这一点? 使用 ,当我列出文件夹时,它以蓝色显示文件夹。 (或者让我们说不同的颜色)但是
我的程序正在向某个日志文件发送characters-colored文本: echo -e "\\033[38;5;2m-->\\033[0m Starting program." | tee $Log
我刚开始使用 gsoap。我只使用 c++ 取得了 4 个小成功,但是我当前的项目限制了我设置源代码生成选项来创建纯 ANSI C(不是 c++)。我似乎无法成功调用该服务,错误返回为 0xC0000
来自 http://blocktronics.org/ 的 ANSI 文件似乎使用的是另一种 ANSI 编码,而不是我的 VT100 终端仿真器支持的编码。 如果我使用 tetraview 查看这些文
如何在 Java 中将十六进制字符串转换为 ansi(窗口 1252)以及将 ansi(窗口 1252)转换为十六进制字符串。 python(完美运行) q = "hex string value"
我用 java 编写了一个 android 应用程序来获取用户答案并将它们保存在一个文件中。问题是这个文件是以 utf-8 格式保存的。最终用户将在 IBM SPSS 中打开这些文件,这是一种适用于
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 7年前关闭。 锁定。这个问题及其答案
这个问题在这里已经有了答案: 关闭 11 年前。 Possible Duplicates: Floating point inaccuracy examples Is JavaScript's Ma
我是一名优秀的程序员,十分优秀!