Yes, I think the manual was not kept up.
sizeof tells me there are 4 bytes to an int.
Just remember, next year it might be 8, or you might get in to embedded
work and come across systems with 16 bit chars (you might not want to
worry about this, I don't for what I'm currently doing).
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.
Depending on what you are doing, you might want to consider (if you are
not already using) as an alternative what is generally used where I used
to work and generally called with "wrap angles" or BAMs (Binary Angular
Measurement, I think). Basically, it was a 16 bit scaled integer where
90 degrees was represented by 0x4000. We generally assumed 2s complement
signed numbers, but with hindsight the code would have worked
identically if the variables were declared as unsigned 16 bit integers
(this was before I found this group and learnt a lot more about C).
Unsigned integers are guaranteed to wrap as you expect.
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.
If UINT_MAX is not declared (or declared incorrectly) through away the
implementation and use something else. First make sure that the error
was not yours!
> I also expected the number to "wrap around" at that value.
Unsigned integer types are guaranteed by the C standard to wrap.
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.
Use "unsigned short" if space is a concern and 16 bits is definitely
large enough. It will be 16 bits on all the systems you are likely to
come across until 128 bit processors come out and desktops by default
come with 16GB of RAM.
I have now implemented more typedefs for this.
Note that short is almost certainly going to be 16 bits on machines with
either 16 or 32 bit int, so using short in your typedef will mean having
to change it less often.
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.
They are good suggestions. There are also various IDEs using gcc. I
suggest you look at
http://clc-wiki.net/wiki/C_resources:Compilers and
http://clc-wiki.net/wiki/C_resources:IDEs
Note that mention on one of those pages is not an endorsement, nor is
being left off a sign it is bad.
Personally I am using gcc for the commercial SW I work on.
I will need to google this. Thank you.
If you search the archives of this group you will find references to a
fairly portable implementation of stdint.h for implementations that do
not provide it.
If would be useful if C had "#ifincexists" to check if an include file
is available, but it does not.