?? voidmain.jr.html
字號(hào):
<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 <robinson@blue.weeg.uiowa.edu><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: <Pine.A32.3.91.950921145742.43918A-100000@black.weeg.uiowa.edu><br>In-Reply-To: <43k3bf$ipk@winx03.informatik.uni-wuerzburg.de> <p>On 18 Sep 1995, Frank Hofmann wrote:<br>> I found this thread very interesting so far. That's why I've tried it myself:<br>> <br>> <TT>void main (void)</TT><br>> <TT>{</TT><br>> <TT> int a, b;</TT><br>> <TT> a = 123; b = 7654;</TT><br>> <TT> printf ("a = %d, b = %d\n", a, b);</TT><br>> <TT> a^=b^=a^=b;</TT><br>> <TT> printf ("a = %d, b = %d\n", a, b);</TT><br>> <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 main(void)</TT>. We changed it to <TT>int 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>
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -