[Assorted-commits] SF.net SVN: assorted: [441] sandbox/trunk/src/c/casts.c
Brought to you by:
yangzhang
From: <yan...@us...> - 2008-02-15 02:46:19
|
Revision: 441 http://assorted.svn.sourceforge.net/assorted/?rev=441&view=rev Author: yangzhang Date: 2008-02-14 18:46:25 -0800 (Thu, 14 Feb 2008) Log Message: ----------- added to cast test Modified Paths: -------------- sandbox/trunk/src/c/casts.c Modified: sandbox/trunk/src/c/casts.c =================================================================== --- sandbox/trunk/src/c/casts.c 2008-02-15 02:45:03 UTC (rev 440) +++ sandbox/trunk/src/c/casts.c 2008-02-15 02:46:25 UTC (rev 441) @@ -1,9 +1,22 @@ #include <stdio.h> int main() { - float x = 1.5; - float y = 2.5; - float f = (int) x + y; - printf("%f", f); - return 0; + { + float x = 1.5; + float y = 2.5; + // The cast has higher precedence than the +, so it casts just x rather than + // sum. + float f = (int) x + y; + printf("%f\n", f); + } + + { + // Don't remember what I was looking for here, but the results seem + // straightforward. + unsigned char c = 0xff; // 255 + unsigned short s = (unsigned short) ((c >> 0) & 0xffU) * 8; // 2040 + printf("%d\n", s); // 2040 + } + + return 0; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |