short or int

C

Chris Hills

SM Ryan <wyrmwif@tango- said:
# The vast majority of MCU in the world do not have VM and are 8 or 16 bit

How many use Ada or assembly instead of C?

Not many.

The last survey I saw had C at about 70% for all embedded systems.
ADA is not common on 8 and 16 bit systems anyway.

Assembler used to be common but less so now. More on some of the smaller
8 bits than 16 bit systems
 
K

Kenneth Brody

Richard said:
john said:


short is not guaranteed to take less space, though.

short is at least 16 bits wide.
int is at least 16 bits wide.

Actually, isn't it more accurate to say "int is at least as wide as short"?
That is, if short is 32 bits, you can't have a 16-bit int, though your
description wouldn't forbid it.

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:[email protected]>
 
S

Simon Biber

Dave said:
If the native word size is 64 bits, wouldn't it make more sense to do
something like this?

short short 16 bits
short 32 bits
int 64 bits
long 64 bits
long long 128 bits

Why even make 'int' and 'long' redundant? Go the whole way and make:

short short 16 bits
short 32 bits
int 64 bits
long 128 bits
long long 256 bits

If you can emulate 128 in software then you can also emulate 256.

The only problem is that 'short short' is not yet a standard C type. You
could always implement it as an extension. Standard-conforming programs
could still access it via <stdint.h>'s int16_t, etc.

Simon.
 
R

Richard Heathfield

Kenneth Brody said:
Actually, isn't it more accurate to say "int is at least as wide as
short"? That is, if short is 32 bits, you can't have a 16-bit int, though
your description wouldn't forbid it.

It's perfectly legal, albeit weird, to have a system like this:

short: 32 bits, of which 16 are padding and 16 are value bits.
int: 16 bits.

So short might be twice as wide as int. What we /can/ say is that SHRT_MAX
<= INT_MAX and SHRT_MIN >= INT_MIN
 
K

Keith Thompson

Herbert Rosenau said:
On an 32 bit system you would use
- char if the value is in range if 8 bit
- short 16
- int 32
- long 32 *
- long long 32 **

* on a 64 bit system it would be 32 or 64 bit
** 64 or 128 bit

On a 16 bit system int will be 16 bit, long 32 bit and long long when
exists 32 bit.

No, long long must always be at least 64 bits.

The term "16 bit system" isn't very well defined. A system with, say,
16-bit CPU registers and/or 16-bit addresses would *probably* have
16-bit ints, but it could legally have 32-bit ints.
 
D

Dave Thompson

Kenneth Brody said:


It's perfectly legal, albeit weird, to have a system like this:

short: 32 bits, of which 16 are padding and 16 are value bits.
int: 16 bits.

So short might be twice as wide as int. What we /can/ say is that SHRT_MAX
<= INT_MAX and SHRT_MIN >= INT_MIN

Sorry, 'width' (and 'wide' and 'narrow' etc.) is defined (in
6.2.6.2p6) as the number of value bits plus sign bit if any.
width and range are indeed required to be nondecreasing, and ranges
also are required to meet minima which require width at least 8 for
char, 16 for short, 16 for int, 32 for long, and 64 for C99 long long.

'size' is the amount of storage in bytes. There is no requirement on
size, except that _all_ objects must be an exact number of bytes.
So with padding size could be decreasing as in your example.

- David.Thompson1 at worldnet.att.net
 
R

Richard Heathfield

Dave Thompson said:

Uh-oh.

Uh-oh!

You always make me nervous, Dave!
Sorry, 'width' (and 'wide' and 'narrow' etc.) is defined (in
6.2.6.2p6) as the number of value bits plus sign bit if any.
width and range are indeed required to be nondecreasing,

Thank you. I'll try to be more precise in future with the concept of
"width".
'size' is the amount of storage in bytes. There is no requirement on
size, except that _all_ objects must be an exact number of bytes.
So with padding size could be decreasing as in your example.

Yes, that was the point I was trying to get across.
 
E

ena8t8si

Dave said:
'size' is the amount of storage in bytes. There is no requirement on
size, except that _all_ objects must be an exact number of bytes.

Almost all. Bitfields are also objects.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,183
Messages
2,570,967
Members
47,520
Latest member
KrisMacono

Latest Threads

Top