Home > Archive > C > June 2006 > Array elements
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| How should I declare the array elements being half word?
and the array elements of the type byte in C??
Please help
Kumar
| |
| Chris Dollin 2006-06-29, 7:56 am |
| Kumar wrote:
> How should I declare the array elements being half word?
There's no such C type: you can't portably do it.
If by "half word" you mean some implementation-specific notion,
you'll have to see what your implementation says. It may be,
for example, that your implementation maps C shorts to what
you're calling a "half word" (but another one does not).
If you can use the C99 specified-int types you might be able
to pick one of those that corresponds to your "half word".
Or ... it may be that you don't need to worry about any of
this nonsense. /Why/ do you want to use "half words"?
> and the array elements of the type byte in C??
In C, the nearest you'll get is a (n unsigned) char. This
may or may not correspond to what you want. Why do you want
to use "type byte"?
--
Chris "th i a signa elem (roun u)" Dollin
"Who do you serve, and who do you trust?" /Cru e/
| |
| Richard Heathfield 2006-06-29, 7:56 am |
| [Cross-posted to comp.lang.c, and followups set to that group]
Kumar said:
> How should I declare the array elements being half word?
That depends on what you mean by "half word". The word "word" is typically
used to describe a collection of bits that naturally fits into a register,
and this varies from machine to machine. The type normally given to such a
collection of bits, in C, is int. Whether a type half the size of an int
exists is up to the compiler writer.
For example, in early MS-DOS C compilers, int was 16 bits, and so was short,
but char was 8 bits, so you could have used char.
Nowadays, Windows compilers tend to set int at 32 bits, but short stays at
16, and char is still 8. So you could use short.
But on some machines, int is 64 bits, and short is 64 bits, and char is 8
bits, so there isn't any basic type available that constitutes a half-word.
> and the array elements of the type byte in C??
There is no 'byte' type in C, but a single char is guaranteed to be exactly
one byte in size (but not necessarily 8 bits!). C defines a byte to be a
unit of storage exactly big enough to store a single char value. It is
CHAR_BIT bits wide, where CHAR_BIT is defined in <limits.h>
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
| |
| Frederick Gotham 2006-06-29, 6:56 pm |
| Chris Dollin posted:
>
> In C, the nearest you'll get is a (n unsigned) char. This
> may or may not correspond to what you want. Why do you want
> to use "type byte"?
I think it's *exactly* what he wants. I consider "char" to be synomonous
with "byte".
(But I don't consider a byte to always be 8 bits.)
--
Frederick Gotham
| |
| Chris Dollin 2006-06-29, 6:56 pm |
| Frederick Gotham wrote:
> Chris Dollin posted:
>
>
> I think it's *exactly* what he wants. I consider "char" to be synomonous
> with "byte".
>
> (But I don't consider a byte to always be 8 bits.)
Until I know what the OP wants "arrays of byte" for, I can't tell if
it's "exactly" what they want.
They might want them for Cunning Type Overlays.
--
Chris "run away! run away!" Dollin
"Life is full of mysteries. Consider this one of them." Sinclair, /Babylon 5/
| |
| Kenneth Brody 2006-06-29, 6:56 pm |
| Richard Heathfield wrote:
>
> [Cross-posted to comp.lang.c, and followups set to that group]
>
> Kumar said:
>
>
> That depends on what you mean by "half word". The word "word" is typically
> used to describe a collection of bits that naturally fits into a register,
> and this varies from machine to machine. The type normally given to such a
> collection of bits, in C, is int. Whether a type half the size of an int
> exists is up to the compiler writer.
[...]
On the KL-10 I used way back when, a "word" was 36 bits, and a "half
word" was (naturally) 18 bits. There were machine-code operators
for working with "half words". (For example, HLRS would move the
left [high-order] half-word of the source address to the "right"
[low-order] half-word of the destination, and sign-extend the
result.)
However, this was before I learned C, so I have no idea how this
would have been handled in C on that system. I also have no idea if
this has anything to do with the OP's use of the term "half word".
--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:ThisIsASpamTrap@gmail.com>
| |
|
| Frederick Gotham wrote:
> I consider "char" to be synomonous with "byte".
I consider those two as synonomous in a string context,
but in a raw memory context,
unsigned char is what to use to manipulate bytes.
--
pete
| |
| santosh 2006-06-29, 6:56 pm |
| Kumar wrote:
> How should I declare the array elements being half word?
Define what "half word" is.
> and the array elements of the type byte in C??
unsigned char array[N] declares an array of N elements of type unsigned
char, which is the unsigned form of byte, as defined by the C standard.
Maybe your definition of byte is different. If so, provide more
specifics.
| |
| Keith Thompson 2006-06-29, 6:56 pm |
| Frederick Gotham <fgothamNO@SPAM.com> writes:
> Chris Dollin posted:
>
> I think it's *exactly* what he wants. I consider "char" to be synomonous
> with "byte".
>
> (But I don't consider a byte to always be 8 bits.)
Maybe. It's certainly true that a char occupies exactly one "byte" by
definition in C, but that's a C-specific definition of the term
"byte". Given that the OP is asking about this in the first place, I
doubt that he's familiar with the C definition.
I don't think there's any further point in speculating about what the
OP really wants. He can come back and clarify what he means.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
|
|
|
|
|