I forget where I got this snippet from.
Anyway, here's the code
I don't think it's for creating arrays ...Code:struct foo { char ch : 8; int aaa : 2; long bbb : 3; };
I forget where I got this snippet from.
Anyway, here's the code
I don't think it's for creating arrays ...Code:struct foo { char ch : 8; int aaa : 2; long bbb : 3; };
I don't know what it's supposed to do, but that stuct will contain 3 signed integers of size 8 bits, 2 bits, and 3 bits. The char, int, and long keywords have no effect in this case except to point out that it is a signed integer type; there is no difference between the three.
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.
ch goes from -128 to 127
aaa from -2 to 1
bbb from -4 to 3
char does not go from -127 to 127 I think. It is a char and it is unsigned. ??
The integer arithmetic can be either two's complement, ones complement or sign-magnitude (though most modern machines use the first). The latter two have a symmetric range, the first has one extra on the minus side. Whether a char is signed or unsigned depends on the compiler (unlike other integral types which are signed by default), so to guarantee one or the other it's necessary to specify signed or unsigned explicitly.
In fact, declaring a signed char is the only place you have to use the keyword signed. (That's why it was introduced, in fact.) Everywhere else it is optional.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.