James Kuyper <ja*********@verizon.netwrites:
arunmib wrote:
> How can I convert an Integer (int data type) and an unsigned char
data type to a quadword? I want to know the conversion mechanism....
I think that veryone has been assuming that what you really wanted to
know was the name the C quadword type. As other people have already
said, while any particular implementation of C might or might not have
an integer type which is 4 words long, the C standard does not specify
which one it is.
However, if you already know the name for the quadword type in a given
implementation of C, it may be that all you're really asking is what
you actually said: "How can I convert ... to a quadword"? If so, the
answer is that the you do it precisely the same way as any other
conversion:
typedef implementation_specific_type quadword;
typedef desired_integer_type Integer;
Integer i = 42;
quadword q = (quadword)i;
unsigned char c = 'c';
q = (quadword)c;
Assuming that "quadword" is an integer type, the casts are
unnecessary. A value can be converted from any numeric type to any
other numeric type with a simple assignment; it will be converted
implicitly:
Integer i = 42;
quadword q = i;
unsighed char c = 'c';
q = c;
If "quadword" *isn't* a numeric type (say, if it's a structure
representing something bigger than the largest available integer
type), then there is no language-defined conversion. If the type is
provided by some library, then that library will probably provide one
or more conversion routines. If you're defining it yourself, you'll
need to define your own conversion routines.
Again, the C language doesn't define a "quadword", or even a "word".
If a "quadword" is meant to be 64 bits, then type "long long" or
"unsigned long long" is probably the right thing; these are integer
types, and can be implicitly converted to or from any other integer
types. They're guaranteed to be *at least* 64 bits; in every
implementation I've heard of they're exactly 64 bits.
If a "quadword" is 4 32-bit words, for a total of 128 bits, there most
likely isn't an integer type that big.
This is why I (and several others) asked the OP to explain to us what
a "quadword" is, and why we can't really answer his question until he
tells us.
--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"