[Assorted-commits] SF.net SVN: assorted: [247] sandbox/trunk/src/c/bitfields.c
Brought to you by:
yangzhang
|
From: <yan...@us...> - 2008-01-20 00:27:12
|
Revision: 247
http://assorted.svn.sourceforge.net/assorted/?rev=247&view=rev
Author: yangzhang
Date: 2008-01-19 16:27:16 -0800 (Sat, 19 Jan 2008)
Log Message:
-----------
bitfields
Added Paths:
-----------
sandbox/trunk/src/c/bitfields.c
Added: sandbox/trunk/src/c/bitfields.c
===================================================================
--- sandbox/trunk/src/c/bitfields.c (rev 0)
+++ sandbox/trunk/src/c/bitfields.c 2008-01-20 00:27:16 UTC (rev 247)
@@ -0,0 +1,19 @@
+#include <stdio.h>
+struct s {
+ // This just means that it is 1 bit wide. It's not standard C (where
+ // bitfields are used only on ints). Seen in JOSMP. Some source on the
+ // Internet (forgot where) mentioned that although these may save space, they
+ // may end up generating a surprising amount of code (depending on the
+ // alignment details).
+ unsigned char c : 1;
+};
+int main() {
+ // These are the only two valid values.
+ struct s s = { 1 };
+ struct s t = { 0 };
+ // This wouldn't work.
+ // struct s u = { 2 };
+ printf("%d %d\n", s.c, t.c);
+ return 0;
+}
+// vim:et:sw=2:ts=2
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|