- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
C 中可能有一些东西会导致 UB。
他们中的大多数都可以这样做,但有几个实现定义的行为会更合乎逻辑。让我举个例子:
关于 <<
运营商,
If E1 has a signed type and nonnegative value, and E1 × 2 E2 is representable in the result type, then that is the resulting value; otherwise, the behavior is undefined.
也就是说
signed char r = 0x40;
r <<= 2;
是 UB,IB 在 IMO 中更合乎逻辑。
是否允许实现定义此处发生的情况?
最佳答案
来自 C 标准:
A conforming hosted implementation shall accept any strictly conforming program... A conforming implementation may have extensions (including additional library functions), provided they do not alter the behavior of any strictly conforming program.
换句话说,实现可以自由地保证特定的行为,否则将是未定义的行为。它无法以改变定义的行为的方式做到这一点。
关于c - "Undefined behaviour"总是未定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24178996/
这个问题在这里已经有了答案: What is the rationale behind decltype behavior? (3 个答案) 关闭 5 年前。 int i = 12; decltyp
这个问题在这里已经有了答案: Undefined, unspecified and implementation-defined behavior (9 个回答) 关闭 4 年前。 C 标准 (AF
我提到了 This Question但没有答案对我有用。所以基本上我有一个 BottomNavigationView,它在向下滚动时隐藏并在向上滚动时显示。当我通过触摸滚动 Recycler View
我正在寻找一种利用mDNS,floodsub和kademlia DHT的网络行为。到目前为止,我已经使所有这些服务都可以使用,但是还不能将这些服务的响应用于有意义的事情。 理想情况下,我将能够将来自行
此代码适用于我的网站: $(function(){ $('.link-follow-stop').on('click', function(event){ console.lo
private synchronized Map calculateStanding() { System.out.println("Calculate standing for
我最近正在测试 的点击事件(点击后找到一个文本框)并发现了一些不寻常的东西。 在 HTML 标记中, 如果在里面, 上面的点击事件标签触发了两次 如果在之外,点击事件为按预期运行 为了更好地理解我要
我尝试了以下两种情况: void ssss(int b){ System.out.println ("int"+b); } void ssss(double b){ System.out.
由于截止日期的压力,我可能会忽略一些东西。但是这种行为令我惊讶。 好像游标缓存了100行,而continue语句刷新了缓存 并从获取新缓存的第一条记录开始。 我将其范围缩小到以下脚本: drop ta
我是德尔福的新手。在 TStrem 类的文档中,我读到它是一个抽象类。所以我认为当我尝试使用 创建它时编译器会出错 stream := TStream.Create(); 为什么不呢? 最佳答案 De
在 Bjarne Stroustrup 的“C++ 之旅”(第二版)的第 18 页上,他指出“对于几乎所有类型,读取或写入未初始化变量的效果是未定义的”。 我明白为什么读取未初始化的变量是未定义的行为
我正在尝试使用两个线程的代码,一个线程递增共享长变量,另一个线程递减 var。 class Shared { private long a; public void incr() {
我们都听过这样的警告:如果您在 C 或 C++ 中调用未定义的行为,任何事情都可能发生。 这是否仅限于任何运行时行为,还是还包括任何编译时行为?特别是,编译器在遇到调用未定义行为的构造时是否允许拒绝代
我在 C++ 中编写了一个简单的函数来计算具有长度、宽度和高度的 Box 对象的体积。这是一个类的一部分,所以 l,b,h是私有(private)成员: long long CalculateVolu
我对以下声明有一些疑问: SELECT 1 FROM dual WHERE DECODE(1, 0, (SELECT COUNT(*) from tbl
我正在做一项作业,要求我编写一些 unix 的 ls 代码。我遇到问题的部分是 -R 选项。 一些背景:我使用的结构包含 2 个列表,一个用于文件,另一个用于运行 ls 时作为参数传递的目录。如果除了
我正在开发一个使用 Spring 数据 的 Java Spring 项目。 它使用 repositories 在狗被主人收集时从 Kennel Object 中移除 Dog Objects。 请注意,
我有一个 NSMutableArray,我分配给它: NSMutableArray *newElements = [[NSMutableArray alloc] initWithObjects:sel
我很少使用 Python,所以我不清楚为什么允许这样的行为:没有 w 对象,因此它没有 s 属性,那为什么 f 允许进行 w.s 赋值? >>> def f(): w.s="ads" #al
我有一个网站,其中一些元素具有 position: fixed。它在桌面浏览器上看起来不错,但在我的手机(Xperia Arc,Android 2.3)上,这些元素会随着页面滚动,直到您从屏幕上松开手
我是一名优秀的程序员,十分优秀!