Re: data types
- From: koolj96825@xxxxxxxxx
- Date: 2 Mar 2007 23:00:30 -0800
16-bit. It may be out of date.
Could be.
Yes, I think the manual was not kept up.
sizeof tells me there are 4 bytes to an int.
Anyway, now that I need to go back over and look closely at my code,
my question is: is there a way to declare a variable say a 16 bit
unsigned integer in C? Or is declaring it "short" the only specifier
that may work?
Why do you need an object of exactly N bits?
I have at least two issues where it matters. In one case, I created a
data type which is similar in concept to a bcd (binary coded decimal)
for working with degrees-minutes-seconds. I am wasting too much
memory per dms structure if they are 32-bit integers. I'll change it
to chars.
Next, I was using them as keys and since some quirk in the compiler
didn't let me use the constant for a max unsigned int, I made my own
constant. I also expected the number to "wrap around" at that value.
Another issue is that I used a bit vector to map out used numbers, as
a 16-bit key, an acceptably small amount of memory would be used up,
but a 32-bit value may be overboard especially since I don't expect
more than a few hundred keys to be in my data structure.
If your compiler is not a C99 one, as it appears to be, then you'll
have to define a 16-bit type yourself. It's not difficult. For
example, if, under your implementation, int happens be 16 bits then
unsigned int is the type you want. You can create an alias like:
typedef unsigned int int16;
I have now implemented more typedefs for this.
But unless you have a specific requirement, I suggest installing a
current compiler system. You have many choices for Windows, though I
recommend either a version of gcc, (Cygwin or MinGW), or Visual Studio
Express.
I only program on the hobby level, although I am doing this project
for my office, I thus have no budget. So, I am using one of the free
compilers. I would love to upgrade but since I do this on the hobby
level, I don't know one compiler from another. I will investigate
your suggestions.
If your implementation does support C99, (and you don't mind partial
support), have a look at the types in stdint.h. uint16_t or
uint_least16_t may meet your needs.
I will need to google this. Thank you.
.
- Follow-Ups:
- Re: data types
- From: Keith Thompson
- Re: data types
- From: Flash Gordon
- Re: data types
- From: santosh
- Re: data types
- References:
- data types
- From: koolj96825
- Re: data types
- From: santosh
- data types
- Prev by Date: Re: Testing pointers in while-loops
- Next by Date: Re: question on variable definitions
- Previous by thread: Re: data types
- Next by thread: Re: data types
- Index(es):
Relevant Pages
|