It's possible to create a data type, for example, a type named "bigint" with 8byte? With bit fields?
Thanks for answer.
This is a discussion on Create data type within the C Programming forums, part of the General Programming Boards category; It's possible to create a data type, for example, a type named "bigint" with 8byte? With bit fields? Thanks for ...
It's possible to create a data type, for example, a type named "bigint" with 8byte? With bit fields?
Thanks for answer.
Do you mean something like:
Code:typedef long long bigint;
Regarding bitfields:
While I don't have the standard around, and that's as much as relevant info I could find, I believe you cannot create a "new type" by simply specifying a larget value than the base type you're going from:C: A Reference Manual, 5th Edition
page 155, pharagraph 1:
A bit field of n bits can represent unsigned integers in the range of 0 through 2^n-1 and
signed integers in the range -2^n-1 through 2^n-1 -1, assuming a twos-complement represen-
tation of signed integers. The origional definition of C permitted only bit fields of type un-
signed, but Standard C permits bit fields to be of type unsigned int,
signed int, or just int, termed unsigned, signed, and plain bit fields. Like plain char-
acters, a plain bit field may be signed or unsigned. Some C implementations allow bit
fields of any integer type including char. C99 allows bit fields of type _Bool.
Page 156, pharagraph 2:
Compilers are free to impose constraints on the maximum size of a bit field and
specify certain addressing boundaries that bit fields cannot cross. These alignment restric-
tions are usually related to the natural word size of the target computer. When a field is too
long for the computer, the compiler will issue an appropriate error message. When a field
would cross a word boundary, it may be moved to the next word.
Page 197, footnote of Table 6-5:
a Bit fields of type int, signed int, or unsigned int are assumed to have a conversion rank less than
int, which means that their converted type depends on whether all their values can be represented in type int.
It only makes sense. Otherwise, you could create nearly infinite numbers:Code:struct superhugenumber { unsigned x:1000; };
I assume, logicly, that you the number specified must fit in an int. So, on a 32 bit machine, we could specify a FOUR BILLION BIT bitfield. Do you really think that would work, or even that it realisticly should work? Not a chance.Code:struct superhugenumber2 { unsigned x:4000000000; }; /* four billion bits! */
Quzah.
Hope is the first step on the road to disappointment.