Thread: Create data type

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    7

    Lightbulb Create data type

    It's possible to create a data type, for example, a type named "bigint" with 8byte? With bit fields?

    Thanks for answer.

  2. #2
    Registered User
    Join Date
    Jun 2004
    Posts
    84
    Do you mean something like:
    Code:
    typedef long long bigint;

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Regarding bitfields:
    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.
    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:
    Code:
    struct superhugenumber
    {
        unsigned x:1000;
    };
    It only makes sense. Otherwise, you could create nearly infinite numbers:
    Code:
    struct superhugenumber2
    {
        unsigned x:4000000000;
    }; /* four billion bits! */
    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.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  2. Can you check what is wrong with this code
    By Ron in forum C++ Programming
    Replies: 4
    Last Post: 08-01-2008, 10:59 PM
  3. singly linked circular list
    By DarkDot in forum C++ Programming
    Replies: 0
    Last Post: 04-24-2007, 08:55 PM
  4. Script errors - bool unrecognized and struct issues
    By ulillillia in forum Windows Programming
    Replies: 10
    Last Post: 12-18-2006, 04:44 AM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM