Re: data types



koolj96825@xxxxxxxxx wrote:
Hi,

I've been working on this project for the past few months in my spare
time, and now I started working on the windows interface and going
over my petzold book, I've come to the realization that an int could
be 32-bit for PCs.

For a particular C implementation an int is (sizeof(int) * CHAR_BIT)
bits. For modern PCs it's often 32 or 64.

Oh, I could kick myself for not checking good in
the beginning, but the manual for the compiler I am using says int is
16-bit. It may be out of date.

Could be.

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?

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;

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.

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.

.



Relevant Pages

  • Re: Should function argument be changed in function body?
    ... >> size_t and %d expects an int... ... > size_t not defined as an 'unsigned int'? ... At least one x86 compiler which had 16 bit int but allowed objects ... a DS9000 series machine, the usual recommendation is to cast it to ...
    (comp.lang.c)
  • Re: data types
    ... sizeof tells me there are 4 bytes to an int. ... 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, ...
    (comp.lang.c)
  • Re: Catching the unsigned int
    ... I have a macro which is called all over a large ... > changing the macro and forcing a compiler error or warning if used ... > with an unsigned long int, ... > So far as I can tell the effect of feeding this an unsigned int is ...
    (comp.lang.c)
  • Re: Incorrect compiler warning C4267
    ... int', possible loss of data uiList.front's data type should be ... reference to unsigned int, so it ought to compile fine. ... MS' compiler attaches to the size_t typedef the additional ... ergo your bogus compiler warning. ...
    (microsoft.public.vc.stl)
  • Re: Integer overflow in expression
    ... > I am using gcc, and I am a bit confused about the warning message I ... a signed int, and then for that signed int product to be ... The compiler is telling you ... 32-bit unsigned int, ...
    (comp.lang.c)