Re: data types



koolj96825@xxxxxxxxx wrote:
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.

Then it's most probably a 32 bit object. What does sizeof(short)
indicate? Usually short is smaller than 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.

Are you trying to pack multiple values into an object? Is the runtime
environment really resource constrained? Unless you use thousands of
such objects, it may not be a significant saving, though of course I'm
speaking from ignorance of your system's limitations.

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.

Your compiler is either *really* old or broken or both. I strongly
suggest replacing it.

I also expected the number to "wrap around" at that value.

If it is equal to (2^n) - 1, where n is the number of value bits in
your object, then it should.

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.

Have you considered a bitfield as an alternative?

<snip>

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.

Both the compilers I mentioned are free to download and use, (though
Microsoft's Visual Studio Express has an onerous EULA). gcc is
absolutely free, available for just about every platform, has very
decent C99 support and is totally free to use. It's a world class
compiler. Most regulars here will recommend gcc to you.

Beware though that gcc by itself doesn't include the standard C
library. However your operating system should include a C library,
which gcc can use.

.



Relevant Pages

  • Re: data types
    ... Usually short is smaller than an int. ... memory per dms structure if they are 32-bit integers. ... current compiler system. ... recommend either a version of gcc,, or Visual Studio ...
    (comp.lang.c)
  • Re: help with type-punned warning please
    ... >using gcc). ... signal processing CPUs -- and objects with types like "int" and ... If some pointer might ... provided the compiler is sufficiently stupid (and/or run with "do ...
    (comp.lang.c)
  • Re: H8S timer configuration problem
    ... > My assumptions here are that you are using GCC, ... > compiler you are using. ... > compiler operates when a divsion implied as int has a long parameter. ... > void main ...
    (comp.arch.embedded)
  • Re: How do header files work?
    ... int a_function{ ... which cannot resolve the call to a_function in the object file produced ... Add the library.c file to the compiler invocation command, ... For gcc do: ...
    (comp.lang.c)
  • visual studio 7.1.6030, bugged? std::random_shuffle or std::vector
    ... hub-bub about visual studio 2003 being broken? ... Tried to make the most simplistic test case as possible. ... would always claim the compiler was broken only to find out it was a ... int main ...
    (microsoft.public.vsnet.general)