{"id":1887,"date":"2024-04-26T06:27:27","date_gmt":"2024-04-25T22:27:27","guid":{"rendered":"https:\/\/wp.minicoda.com\/?p=1887"},"modified":"2024-11-06T18:07:02","modified_gmt":"2024-11-06T10:07:02","slug":"%e6%95%b0%e5%80%bc%e6%ba%a2%e5%87%ba%e4%bf%9d%e6%8a%a4","status":"publish","type":"post","link":"https:\/\/wp.minicoda.com\/index.php\/%e6%95%b0%e5%80%bc%e6%ba%a2%e5%87%ba%e4%bf%9d%e6%8a%a4\/","title":{"rendered":"\u6570\u503c\u6ea2\u51fa\u4fdd\u62a4"},"content":{"rendered":"\n<p>  C\/ObjC\/C++\u5728\u6570\u503c\u6ea2\u51fa\u65f6\u5e76\u672a\u505a\u8fc7\u591a\u4fdd\u62a4\uff0c\u8d23\u4efb\u63a8\u7ed9\u4e86\u7a0b\u5e8f\u5458\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>C\/ObjC\/C++\u9009\u62e9\u76f8\u4fe1\u7a0b\u5e8f\u5458\u80fd\u63a7\u5236\u6ea2\u51fa\uff0c\u4e0d\u8fc7\u6709\u7684\u7f16\u8bd1\u5668\u4f1a\u63d0\u4f9b\u6ea2\u51fa\u9884\u9632\u7b56\u7565\u3002<br>char c = 128;  \/\/ \u5047\u8bbechar\u662f\u6709\u7b26\u53f71\u5b57\u8282<br>-  GCC\/G++\u4e0d\u4f1a\u63d0\u793a\u4efb\u4f55\u95ee\u9898\uff0cgcc11.4\u5373\u4f7f\u7528-Woverflow\u4e5f\u4e0d\u4f1a\u6709\u4efb\u4f55\u63d0\u793a\u3002<br>-  Clang\u4f1a\u63d0\u793a\u8b66\u544a\uff1aimplicit conversion from 'int' to 'char' changes value from 128 to -128<\/li>\n\n\n\n<li>Go\u8bed\u8a00\u548cC\u8bed\u8a00\u7c7b\u4f3c\uff0c\u9009\u62e9\u76f8\u4fe1\u7a0b\u5e8f\u5458\u80fd\u63a7\u5236\u6ea2\u51fa\uff0c\u53d1\u751f\u6ea2\u51fa\u4e0d\u4f1a\u6709\u4efb\u4f55\u9519\u8bef\u3002<\/li>\n\n\n\n<li>Swift\u662f\u8bbe\u8ba1\u5b89\u5168\u7684\u8bed\u8a00\uff0c\u7f16\u8bd1\u671f\u95f4\u53d1\u73b0\u6570\u503c\u5b58\u50a8\u4e0d\u5339\u914d\uff0c\u4f1a\u76f4\u63a5\u62a5\u9519\uff0c\u8fd0\u884c\u671f\u53d1\u73b0\u6ea2\u51fa\u4e5f\u4f1a\u62a5\u9519<br>let a: UInt8 = -1<br>\u540c\u65f6\uff0cSwift\u4e5f\u63d0\u4f9b\u4e86\u6ea2\u51fa\u8fd0\u7b97\u7b26\uff08\u5982<code>&amp;+<\/code>\u3001<code>&amp;-<\/code>\u3001<code>&amp;*<\/code>\u7b49\uff09\u6765\u663e\u5f0f\u5904\u7406\u53ef\u80fd\u6ea2\u51fa\u7684\u60c5\u51b5\u3002<\/li>\n\n\n\n<li>C#\u9ed8\u8ba4\u4e5f\u4e0d\u4f1a\u5bf9\u8fd0\u884c\u671f\u6ea2\u51fa\u505a\u5904\u7406\uff0c\u4f46\u53ef\u5229\u7528\u7f16\u8bd1\u5668\u9009\u9879\/checked\u6216\u8005checked\u64cd\u4f5c\u7b26\/\u8bed\u53e5\u505a\u5168\u5c40\u3001\u5c40\u90e8\u6ea2\u51fa\u68c0\u67e5\uff0c\u4e00\u65e6\u53d1\u73b0\u6ea2\u51fa\u5c06\u629b\u51fa\u5f02\u5e38\u3002\n<ul class=\"wp-block-list\">\n<li>\u4ee3\u7801\u6216\u8005\u7f16\u8bd1\u9009\u62e9\u6307\u5b9achecked\uff0c\u4e00\u5b9a\u4f1a\u6709\u6ea2\u51fa\u68c0\u67e5\uff1b\u5982\u679c\u4ee3\u7801\u4e2d\u6307\u5b9aunchecked, \u4f1a\u5ffd\u7565\u7f16\u8bd1\u9009\u9879\/checked.<\/li>\n\n\n\n<li>\u6ce8\u610f\uff0c\u5982\u679c\u7528\u5e38\u91cf\u8d4b\u503c\u53d1\u751f\u6ea2\u51fa\uff0c\u5982short a = 32767\uff0c\u7f16\u8bd1\u5668\u4f1a\u76f4\u63a5\u62a5\u9519\uff1a\u5e38\u91cf\u503c\u201c32768\u201d\u65e0\u6cd5\u8f6c\u6362\u4e3a\u201cshort\u201d<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Java\u548cC#\u4e00\u6837\u5e38\u91cf\u8d4b\u503c\u9003\u4e0d\u8fc7\u7f16\u8bd1\u5668\u68c0\u67e5\uff0c\u9ed8\u8ba4\u4e5f\u4e0d\u4f1a\u5bf9\u8fd0\u884c\u671f\u6ea2\u51fa\u505a\u5904\u7406\uff0c\u8fd0\u884c\u671f\u53ef\u5229\u7528\u7279\u5b9aAPI\u505a\u6ea2\u51fa\u68c0\u67e5\uff0c\u6bd4\u5982\u52a0\u6cd5\u68c0\u67e5Math.addExact\u65b9\u6cd5\u3002<br>int a = Integer.MAX_VALUE;<br>try {<br>&nbsp;&nbsp;&nbsp;&nbsp;int result = Math.addExact(a, 1);<br>} catch (ArithmeticException e) {<br>&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(\"Overflow exceptoin\uff1a\" + e.getMessage());<br>}<\/li>\n\n\n\n<li>Python 3\u7528long\u66ff\u4ee3int, long\u51e0\u4e4e\u662f\u65e0\u7a77\u5927(\u9664\u975e\u8ba1\u7b97\u673a\u5185\u5b58\u65e0\u6cd5\u5b58\u50a8long\u5b57\u7b26\u4e32)\uff0c\u6570\u503c\u6ea2\u51fa\u5f88\u5c11\u51fa\u73b0\u5728Python.<\/li>\n\n\n\n<li>JS\u4f5c\u4e3a\u811a\u672c\u8bed\u8a00\uff0c\u6ea2\u51fa\u662f\u4e2a\u5f88\u5c11\u8003\u8651\u7684\u8bdd\u9898\u3002\u6570\u503cNumber\u7c7b\u578b\u6700\u5927\u5b89\u5168\u503cMAX_SAFE_INTEGER\u8d85\u8fc7\u4e07\u4ebf\uff0c\u5982\u679c\u4e0d\u6ee1\u8db3\u8fd8\u53ef\u7528\u66f4\u5927\u7684BigInt.<\/li>\n\n\n\n<li>VB.NET\u4e4b\u524d\u7f16\u8bd1\u9636\u6bb5\u4e0d\u4f1a\u63d0\u793a\u6ea2\u51fa\uff0c\u8fd0\u884c\u671f\u6ea2\u51fa\u4f1a\u62a5\u9519\u3002VB.NET\u7f16\u8bd1\u671f\u5373\u53ef\u62a5\u9519\u3002<br>  - \u4f8b\u5982\uff1aDim bigNumber As Integer = Int32.MaxValue + 1<br>     \u62a5\u9519\uff1a\u5e38\u91cf\u8868\u8fbe\u5f0f\u65e0\u6cd5\u5728\u7c7b\u578b\u201cInteger\u201d\u4e2d\u8868\u793a\u3002<\/li>\n\n\n\n<li>Rust\u4f5c\u4e3a\u4e00\u95e8\u5b89\u5168\u653e\u5728\u9996\u4f4d\u7684\u8bed\u8a00\uff0c\u7f16\u8bd1\u671f\u53d1\u73b0\u6ea2\u51fa\u4f1a\u62a5\u9519\u3002<br>let a: u32 = u32::MAX + 1;  \/\/ \u62a5\u9519\uff1aarithmetic operation will overflow\n<ul class=\"wp-block-list\">\n<li>\u540c\u65f6Rust\u63d0\u4f9b\u4e00\u7cfb\u5217API\u53cd\u9988\u662f\u5426\u4f1a\u6ea2\u51fa\u3001\u6ea2\u51fa\u540e\u662f\u56de\u7ed5\u8fd8\u662f\u8bbe\u5b9a\u6700\u5927\/\u6700\u5c0f\u503c\u3002<br>\u4ee5\u52a0\u6cd5\u4e3a\u4f8b\uff0cchecked_add\u53d1\u751f\u6ea2\u51fa\u8fd4\u56deNone\uff0coverflowing_add\u8fd4\u56de\u6ea2\u51fa\u4e0e\u5426\u6807\u5fd7\u548c\u8ba1\u7b97\u503c\uff0csaturating_add\u6839\u636e\u662f\u4e0a\u6ea2\u8fd8\u662f\u4e0b\u6ea2\u8bbe\u7f6e\u4e3a\u80fd\u8868\u8fbe\u7684\u6700\u5927\u6216\u6700\u5c0f\u503c\uff0cwrapping_add\u4f1a\u5728\u53d1\u751f\u6ea2\u51fa\u65f6\u56de\u7ed5\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>\u4ed3\u9889 \u9047\u5230\u6ea2\u51fa\u7684\u5b57\u9762\u91cf\uff0c\u4e00\u6837\u4f1a\u7f16\u8bd1\u51fa\u9519\u3002<br>var i: UInt8 = 300<br>\u62a5\u9519\uff1athe number '300' exceeds the value range of type 'UInt8'<\/li>\n\n\n\n<li>PHP\u8d85\u51fa\u6574\u6570\u8303\u56f4\u7684\u6570\u503c\u4f1a\u81ea\u52a8\u8f6c\u6362\u6210\u6d6e\u70b9\u6570\u4ee5\u4fdd\u8bc1\u6570\u503c\u6b63\u786e\u3002<\/li>\n<\/ul>\n\n\n\n<p>       <\/p>\n","protected":false},"excerpt":{"rendered":"<p>C\/ObjC\/C++\u5728\u6570\u503c\u6ea2\u51fa\u65f6\u5e76\u672a\u505a\u8fc7\u591a\u4fdd\u62a4\uff0c\u8d23\u4efb\u63a8\u7ed9\u4e86\u7a0b\u5e8f\u5458\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[299],"tags":[],"class_list":["post-1887","post","type-post","status-publish","format-standard","hentry","category-think"],"views":90,"_links":{"self":[{"href":"https:\/\/wp.minicoda.com\/index.php\/wp-json\/wp\/v2\/posts\/1887","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wp.minicoda.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wp.minicoda.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wp.minicoda.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wp.minicoda.com\/index.php\/wp-json\/wp\/v2\/comments?post=1887"}],"version-history":[{"count":12,"href":"https:\/\/wp.minicoda.com\/index.php\/wp-json\/wp\/v2\/posts\/1887\/revisions"}],"predecessor-version":[{"id":3297,"href":"https:\/\/wp.minicoda.com\/index.php\/wp-json\/wp\/v2\/posts\/1887\/revisions\/3297"}],"wp:attachment":[{"href":"https:\/\/wp.minicoda.com\/index.php\/wp-json\/wp\/v2\/media?parent=1887"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wp.minicoda.com\/index.php\/wp-json\/wp\/v2\/categories?post=1887"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wp.minicoda.com\/index.php\/wp-json\/wp\/v2\/tags?post=1887"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}