Thread: Signed Ints??
View Single Post
  #4   Spotlight this post!  
Unread 22-02-2004, 11:50
mtrawls's Avatar
mtrawls mtrawls is offline
I am JVN! (John von Neumann)
#0122 (NASA Knights)
Team Role: Programmer
 
Join Date: Mar 2003
Location: Hampton, VA
Posts: 295
mtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to behold
Send a message via AIM to mtrawls
Re: Signed Ints??

Quote:
Originally Posted by SuperDanman
Kinda on a similair topic, how can you create a single-bit variable - kinda like a bool - using c?

This whitepaper says you can use individual bits like so:

Code:
struct bits {
unsigned int itsy: 3; // Use 3 bits as the variable ?itsy?
unsigned int bitsy: 3; // Use 3 bits as the variable ?bitsy?
unsigned int teensy: 1; // Use 1 bit as the variable ?teensy?
unsigned int weensey:1 // Use 1 bit at the variable ?weensy?
};
but the "itsey: 3;" syntax doesn't seem to work unless you are using it inside a struct. I'm sure there's a way more elegant than using a struct, but can anyone let me know what it is?
Well, that's C for you. If you want to work with bits, you're stuck with bitfields as the most elegant solution. Of course, you could use ints and just use macros to get at the bits -- but that is messy, and why not let the compiler do it for you automagically with the bitfield? There's a struct already declared for you by IFI in the default code that gives you access to bits 1 - 8. If you desire true "elegance" might I suggest just hiding everything behind a define statement -- e.g., #define mybit bitfield.bit5.