⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 voidmain.jr.html

📁 this is a mirrored site c-faq. thought might need offline
💻 HTML
字号:
<html><!-- Mirrored from c-faq.com/ansi/voidmain.jr.html by HTTrack Website Copier/3.x [XR&CO'2008], Sat, 14 Mar 2009 08:02:59 GMT --><head></head><body>From: The Amorphous Mass &lt;robinson@blue.weeg.uiowa.edu&gt;<br>Newsgroups: comp.lang.c<br>Subject: Re: <TT>a ^= b ^= a ^= b</TT> ???<br>Date: Thu, 21 Sep 1995 15:04:13 -0500<br>Message-ID: &lt;Pine.A32.3.91.950921145742.43918A-100000@black.weeg.uiowa.edu&gt;<br>In-Reply-To: &lt;43k3bf$ipk@winx03.informatik.uni-wuerzburg.de&gt; <p>On 18 Sep 1995, Frank Hofmann wrote:<br>&gt; I found this thread very interesting so far. That's why I've tried it myself:<br>&gt; <br>&gt; <TT>void main (void)</TT><br>&gt; <TT>{</TT><br>&gt; <TT>&nbsp;&nbsp;int a, b;</TT><br>&gt; <TT>&nbsp;&nbsp;a = 123; b = 7654;</TT><br>&gt; <TT>&nbsp;&nbsp;printf ("a = %d, b = %d\n", a, b);</TT><br>&gt; <TT>&nbsp;&nbsp;a^=b^=a^=b;</TT><br>&gt; <TT>&nbsp;&nbsp;printf ("a = %d, b = %d\n", a, b);</TT><br>&gt; <TT>}</TT><p>This code <em>crashes</em> my coworker's Toshiba laptop, not because of the <TT>^=</TT>bit, but because of the <TT>void&nbsp;main(void)</TT>.  We changed it to <TT>int&nbsp;main(void)</TT>and it worked as you hope it works.<p>We were running under BC++ 4.5.<p>However, the fact that it works on every compiler on every platform you can find means little.  It works because the compilers are nice enough to correctly guess what you want out of "<TT>a^=b^=a^=b</TT>," not because it's correct or clear.  The result of that expression is undefined; if there are scads of compilers that guess the intended result, then there are a lot of people getting away with sloppy programs.<p>As someone else has no doubt pointed out, the compiler is as free to overwrite your hard drive as it is to swap the values of <TT>a</TT> and <TT>b</TT> in the above program.<p>Just for the heck of it, I'll see what THINK C 5.0 makes of it.<p><pre>___________Bushido, n.: the ancient art of keeping your  | James Robinsoncool when a US President ralphs in your lap.  | james-f-robinson@uiowa.edu</pre></body><!-- Mirrored from c-faq.com/ansi/voidmain.jr.html by HTTrack Website Copier/3.x [XR&CO'2008], Sat, 14 Mar 2009 08:02:59 GMT --></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -