unsigned 和 signed 的比較 (怪)

unsigned int i=1;
int j=-1
if(i>j) printf(“i>j”);
else printf(“j>i);

用VS2008 C++竟然出現 j>i。

uint i=1;
if(i>j) Console.Write(“i>j”);
else Console.Write(“j>i);

這次用C#就印出正常的 i>j。

This entry was posted in 電腦和網際網路. Bookmark the permalink.

One Response to unsigned 和 signed 的比較 (怪)

  1. Luse says:

    C# 跟 C 遇到這種狀況的處理是不太一樣 如果是C 的話 依ISO C99 的 Rule 這樣的狀況 j>i 的確是符合Spec的如果是C#的話 在Spec內提到這種狀況應該做promotion 所以會有這樣的結果也是對的

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s