[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
这个话题我想讲很久了,主要在于很多萌新问出的这些学校的题目过于离谱而且没有意义,必须说一下。
什么是未定义行为?单纯的来说就是标准委员会也没有规定到底在那些情况下要发生什么结果,编译器产生的是未知的(虽然大部分时候是可以知道的)。有很多没有任何意义的题目,我们一一列举
#include<iostream> #include<string> void func(int a, int b) { std::cout << a
<< " " << b << std::endl; } int main() { int i = 0; func(i++, i++); return 0; }
上面是在MSVC,cpp的debug得出的结果,未开启优化 ,下面是release模式下的结果
其实这还可能涉及入栈的问题,我们讨论下一个
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<math.h>
#include<string.h> int main() { int i = 0; printf("%d %d %d %d", i++, i++, i--,
--i); return 0; }
上面的是MSVC debug模式下的结果,下面是release
这个例子我必须重点强调,会因为编译器的不同导致不同结果,且学校最喜欢这么出,可见出题人水平,标准的未定义行为,在c prime plus c++ prime
plus等热门的基础书都提过这种行为,别的不说,我起码还能找出三四种结果,使用gcc编译,或者手机编译器等等。
还有很多的未定义行为,我们不再一一列举,总之有些问题是没有意义的,我也清楚MSVC对于那种情况是按照入栈与一个寄存器,但是,依旧没有意义,实际开发不可能写这种代码,我不再讲更深入的,这是给萌新了解一下的