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: Memory allignment/type casting question
    ... int main ... Even if those pointers do point into the array 'c', the behavior is still undefined, because you're accessing the memory through an lvalue of a type that isn't compatible with the effective type of the object stored in that location. ... In practice, for an implementations without alignment restrictions on unsigned int, the result should be to interpret the appropriate bytes of 'c' as if they were unsigned int. ... Perhaps if you identify the compiler, the operating system, and the CPU, someone else can give you a better explanation for those results than I can. ...
    (comp.lang.c)
  • 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: 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: 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)