Sizes of Integer Types

Discussion in 'C Programming' started by Bob Timpkinson, Sep 5, 2007.

  1. Hi,

    I have a 32-bit machine... Is there anyway I can get gcc to use the
    following integer sizes?
    char: 8 bits
    short: 16 bits
    int: 32 bits
    long: 64 bits
    long long: 128 bits

    Thanks!

    Bob.
    Bob Timpkinson, Sep 5, 2007
    #1
    1. Advertising

  2. Bob Timpkinson

    jacob navia Guest

    Bob Timpkinson wrote:
    > Hi,
    >
    > I have a 32-bit machine... Is there anyway I can get gcc to use the
    > following integer sizes?
    > char: 8 bits
    > short: 16 bits
    > int: 32 bits
    > long: 64 bits
    > long long: 128 bits
    >
    > Thanks!
    >
    > Bob.
    >


    No way unless:
    1) You download the source code of gcc
    2) Change quite a few things inside

    You would have to work for approx 6 months to 2 years depending
    on your luck and knowledge about compilers

    Just as a gcc user I see no way to do that.

    But why you want that in the first place?
    jacob navia, Sep 5, 2007
    #2
    1. Advertising

  3. Bob Timpkinson <> writes:
    > I have a 32-bit machine... Is there anyway I can get gcc to use the
    > following integer sizes?
    > char: 8 bits
    > short: 16 bits
    > int: 32 bits
    > long: 64 bits
    > long long: 128 bits


    We don't know. Try asking in gnu.gcc.help.

    --
    Keith Thompson (The_Other_Keith) <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."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
    Keith Thompson, Sep 5, 2007
    #3
  4. On Wed, 5 Sep 2007 09:18:00 +0200 (CEST), in comp.lang.c , Bob
    Timpkinson <> wrote:

    >Hi,
    >
    >I have a 32-bit machine... Is there anyway I can get gcc to use the
    >following integer sizes?
    >char: 8 bits
    >short: 16 bits
    >int: 32 bits
    >long: 64 bits
    >long long: 128 bits


    Why would you want to?
    Compilers are built to match the hardware / software environment
    they're targetting.

    --
    Mark McIntyre

    "Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are,
    by definition, not smart enough to debug it."
    --Brian Kernighan
    Mark McIntyre, Sep 5, 2007
    #4
  5. I don't believe that's true - surely any C compiler worth its salt will
    allow you to set this sort of option?

    It seems logical to me to give every integer size its own type, and then
    you can program with confidence knowing how big each variable will be.

    Bob.

    On 5 Sep 2007 at 7:22, jacob navia wrote:
    > Bob Timpkinson wrote:
    >> Hi,
    >>
    >> I have a 32-bit machine... Is there anyway I can get gcc to use the
    >> following integer sizes?
    >> char: 8 bits
    >> short: 16 bits
    >> int: 32 bits
    >> long: 64 bits
    >> long long: 128 bits
    >>
    >> Thanks!
    >>
    >> Bob.
    >>

    >
    > No way unless:
    > 1) You download the source code of gcc
    > 2) Change quite a few things inside
    >
    > You would have to work for approx 6 months to 2 years depending
    > on your luck and knowledge about compilers
    >
    > Just as a gcc user I see no way to do that.
    >
    > But why you want that in the first place?
    Bob Timpkinson, Sep 5, 2007
    #5
  6. Bob Timpkinson

    jacob navia Guest

    Bob Timpkinson wrote:
    > I don't believe that's true - surely any C compiler worth its salt will
    > allow you to set this sort of option?
    >
    > It seems logical to me to give every integer size its own type, and then
    > you can program with confidence knowing how big each variable will be.
    >
    > Bob.
    >


    I repeat:
    There is NO C compiler that allows you to change the sizes of the
    basic types. Period.

    Please show me one C compiler that does that.

    jacob
    jacob navia, Sep 5, 2007
    #6
  7. Bob Timpkinson

    Ben Pfaff Guest

    Bob Timpkinson <> writes:

    > I have a 32-bit machine... Is there anyway I can get gcc to use the
    > following integer sizes?
    > char: 8 bits
    > short: 16 bits
    > int: 32 bits
    > long: 64 bits
    > long long: 128 bits


    gnu.gcc.help is a better place for this kind of question.
    Followups set.

    <OFF-TOPIC>
    I don't think so. In particular, I don't think GCC has support
    for quad-word 128-bit arithmetic, except for use with
    processor-specific built-in functions for e.g. SSE support.
    </OFF-TOPIC>
    --
    "I hope, some day, to learn to read.
    It seems to be even harder than writing."
    --Richard Heathfield
    Ben Pfaff, Sep 5, 2007
    #7
  8. Bob Timpkinson

    Flash Gordon Guest

    jacob navia wrote, On 05/09/07 20:17:
    > Bob Timpkinson wrote:
    >> I don't believe that's true - surely any C compiler worth its salt will
    >> allow you to set this sort of option?
    >>
    >> It seems logical to me to give every integer size its own type, and then
    >> you can program with confidence knowing how big each variable will be.

    >
    > I repeat:
    > There is NO C compiler that allows you to change the sizes of the
    > basic types. Period.
    >
    > Please show me one C compiler that does that.


    gcc 3.3.3
    -m96bit-long-double/-m128-bit-long-double
    -m32/-m64

    Or then there are some of the old 80x86 compilers that allowed you to
    select one of a number of sies for pointers.

    Of course, you cannot select any values you want, and you can't select
    what the OP wanted, but you *can* change them between allowed values.
    --
    Flash Gordon
    Flash Gordon, Sep 5, 2007
    #8
  9. In article <>,
    Bob Timpkinson <> top-posted (now corrected):

    >On 5 Sep 2007 at 7:22, jacob navia wrote:
    >> Bob Timpkinson wrote:


    >>> I have a 32-bit machine... Is there anyway I can get gcc to use the
    >>> following integer sizes?
    >>> char: 8 bits
    >>> short: 16 bits
    >>> int: 32 bits
    >>> long: 64 bits
    >>> long long: 128 bits


    >> No way unless:
    >> 1) You download the source code of gcc
    >> 2) Change quite a few things inside


    >I don't believe that's true - surely any C compiler worth its salt will
    >allow you to set this sort of option?


    No, they seldom do. Once you get beyond the arithmetic capabilities
    supported by the hardware, operations such as 128 addition or
    division must be synthesized in software. In order for a compiler
    to allow you to set the type sizes arbitrarily high and support
    all the usual arithmetic upon the types, it would have to know how
    to generate software integral and floating point operations at
    arbitrarily high precisions.

    If you are going to support software operations at arbitrarily high
    precisions, then instead of expecting the compiler to handle it, it is
    usually better to use one of the several indefinite precision
    arithemetic packages that are available. You can get packages that
    will, for example, support (5**1000 - 4**1000) / 3**1000
    and give you the result to (say) 317 decimal places if that's
    what you want. Or to 800 decimal places, whatever you ask for
    (and that fits into memory). Or which will return the result
    as a rational number if that's what you prefer. This work has
    been done already.
    --
    Okay, buzzwords only. Two syllables, tops. -- Laurie Anderson
    Walter Roberson, Sep 5, 2007
    #9
  10. Bob Timpkinson

    jacob navia Guest

    Flash Gordon wrote:
    > jacob navia wrote, On 05/09/07 20:17:
    >> Bob Timpkinson wrote:
    >>> I don't believe that's true - surely any C compiler worth its salt will
    >>> allow you to set this sort of option?
    >>>
    >>> It seems logical to me to give every integer size its own type, and then
    >>> you can program with confidence knowing how big each variable will be.

    >>
    >> I repeat:
    >> There is NO C compiler that allows you to change the sizes of the
    >> basic types. Period.
    >>
    >> Please show me one C compiler that does that.

    >
    > gcc 3.3.3
    > -m96bit-long-double/-m128-bit-long-double
    > -m32/-m64
    >
    > Or then there are some of the old 80x86 compilers that allowed you to
    > select one of a number of sies for pointers.
    >
    > Of course, you cannot select any values you want, and you can't select
    > what the OP wanted, but you *can* change them between allowed values.


    This is a completely different thing and you know it.
    jacob navia, Sep 5, 2007
    #10
  11. jacob navia <> writes:
    > Bob Timpkinson wrote:
    >> I don't believe that's true - surely any C compiler worth its salt will
    >> allow you to set this sort of option?
    >> It seems logical to me to give every integer size its own type, and
    >> then
    >> you can program with confidence knowing how big each variable will be.

    >
    > I repeat:
    > There is NO C compiler that allows you to change the sizes of the
    > basic types. Period.
    >
    > Please show me one C compiler that does that.


    You really should stop and think for a moment before making sweeping
    statements like that.

    Here's the source file "c.c" that I use for all three tests:
    #include <stdio.h>
    int main(void)
    {
    printf("sizeof(long) = %d\n", (int)sizeof(long));
    return 0;
    }

    On SPARC Solaris 9:
    ================================
    % cc -V
    cc: Sun C 5.5 Patch 112760-18 2005/06/14
    usage: cc [ options] files. Use 'cc -flags' for details
    % cc c.c -o c && ./c
    sizeof(long) = 4
    % cc -xtarget=ultra -xarch=v9 c.c -o c && ./c
    sizeof(long) = 8
    ================================

    On Fedora x86-64:
    ================================
    % gcc --version | head -1
    gcc (GCC) 4.1.2 20070626 (Red Hat 4.1.2-13)
    % gcc -m32 c.c -o c && ./c
    sizeof(long) = 4
    % gcc -m64 c.c -o c && ./c
    sizeof(long) = 8
    ================================

    On AIX PowerPC:
    ================================
    % xlc -qversion
    IBM XL C/C++ Enterprise Edition V8.0 for AIX
    Version: 08.00.0000.0011
    % xlc -q32 c.c -o c && ./c
    sizeof(long) = 4
    % xlc -q64 c.c -o c && ./c
    sizeof(long) = 8
    ================================

    I don't know of any compilers that allow you to specify the sizes of
    *all* the predefined integer types.

    --
    Keith Thompson (The_Other_Keith) <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."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
    Keith Thompson, Sep 5, 2007
    #11
  12. Bob Timpkinson

    Flash Gordon Guest

    jacob navia wrote, On 05/09/07 20:43:
    > Flash Gordon wrote:
    >> jacob navia wrote, On 05/09/07 20:17:
    >>> Bob Timpkinson wrote:
    >>>> I don't believe that's true - surely any C compiler worth its salt will
    >>>> allow you to set this sort of option?
    >>>>
    >>>> It seems logical to me to give every integer size its own type, and
    >>>> then
    >>>> you can program with confidence knowing how big each variable will be.
    >>>
    >>> I repeat:
    >>> There is NO C compiler that allows you to change the sizes of the
    >>> basic types. Period.
    >>>
    >>> Please show me one C compiler that does that.

    >>
    >> gcc 3.3.3
    >> -m96bit-long-double/-m128-bit-long-double
    >> -m32/-m64
    >>
    >> Or then there are some of the old 80x86 compilers that allowed you to
    >> select one of a number of sies for pointers.
    >>
    >> Of course, you cannot select any values you want, and you can't select
    >> what the OP wanted, but you *can* change them between allowed values.

    >
    > This is a completely different thing and you know it.


    It is changing the sizes of basic types, something you said was
    categorically not provided by any compiler. It is doing it without
    switching to a different platform or OS. If you state something as an
    absolute, you should expect people to call you on it.

    For another processor gcc has the option to make int 16 bits. For yet
    another you can select whether int is 32 or 64 bits.

    The simple fact is that you were wrong to say that no compilers allow
    you to change the size of basic types, and even more wrong to be so
    emphatic about it, because some do for some targets.
    --
    Flash Gordon
    Flash Gordon, Sep 5, 2007
    #12
  13. jacob navia <> writes:
    > Flash Gordon wrote:
    >> jacob navia wrote, On 05/09/07 20:17:
    >>> Bob Timpkinson wrote:
    >>>> I don't believe that's true - surely any C compiler worth its salt will
    >>>> allow you to set this sort of option?
    >>>>
    >>>> It seems logical to me to give every integer size its own type, and then
    >>>> you can program with confidence knowing how big each variable will be.
    >>>
    >>> I repeat:
    >>> There is NO C compiler that allows you to change the sizes of the
    >>> basic types. Period.
    >>>
    >>> Please show me one C compiler that does that.

    >> gcc 3.3.3
    >> -m96bit-long-double/-m128-bit-long-double
    >> -m32/-m64
    >> Or then there are some of the old 80x86 compilers that allowed you
    >> to select one of a number of sies for pointers.
    >> Of course, you cannot select any values you want, and you can't
    >> select what the OP wanted, but you *can* change them between allowed
    >> values.

    >
    > This is a completely different thing and you know it.


    It's different from what you probably meant. It's exactly the same as
    what you said:

    There is NO C compiler that allows you to change the sizes of the
    basic types. Period.

    --
    Keith Thompson (The_Other_Keith) <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."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
    Keith Thompson, Sep 5, 2007
    #13
  14. In article <>,
    Bob Timpkinson <> wrote:

    >I don't believe that's true - surely any C compiler worth its salt will
    >allow you to set this sort of option?


    >It seems logical to me to give every integer size its own type, and then
    >you can program with confidence knowing how big each variable will be.


    And how are you going to call the system libraries, which assume the
    usual sizes? You can probably rebuild gcc to use different sizes, but
    doing it on the fly is not worth it.

    It would be easier to typedef all your integer types in terms of n-bit
    types, or if you really want to you could use macros and define them
    on the command line.

    -- Richard
    --
    "Consideration shall be given to the need for as many as 32 characters
    in some alphabets" - X3.4, 1963.
    Richard Tobin, Sep 5, 2007
    #14
  15. On Wed, 5 Sep 2007 21:13:29 +0200 (CEST), in comp.lang.c , Bob
    Timpkinson <> wrote:

    >I don't believe that's true - surely any C compiler worth its salt will
    >allow you to set this sort of option?


    Why?

    >It seems logical to me to give every integer size its own type,


    You'd better add in 7,9,18,36 and the other bitsizes then, there's
    _lots_ of integer sizes out there in the wide world.....

    >and then
    >you can program with confidence knowing how big each variable will be.


    For a given implementation, you /do/ know. If you're writing code that
    really really depends on the sizes, you probably either have an
    algorithm error, or you're doing something hardware specific anyway.

    --
    Mark McIntyre

    "Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are,
    by definition, not smart enough to debug it."
    --Brian Kernighan
    Mark McIntyre, Sep 5, 2007
    #15
  16. >I don't believe that's true - surely any C compiler worth its salt will
    >allow you to set this sort of option?


    Surely not (although some compilers give you a limited choice with
    "memory models"). Can you imagine the number of different C libraries
    you would need for all the possible different combinations of data
    type sizes?

    >It seems logical to me to give every integer size its own type, and then
    >you can program with confidence knowing how big each variable will be.


    It seems logical to me that you cannot know what version of what compiler
    will be used by someone else to compile the code.

    There are a number of people who "know" (incorrectly) things like
    sizeof(int) == sizeof(int *), sizeof(int) == sizeof(long), and
    sizeof(int) == 4.
    Gordon Burditt, Sep 6, 2007
    #16
  17. Bob Timpkinson

    Eric Sosman Guest

    jacob navia wrote:
    > Bob Timpkinson wrote:
    >> I don't believe that's true - surely any C compiler worth its salt will
    >> allow you to set this sort of option?
    >>
    >> It seems logical to me to give every integer size its own type, and then
    >> you can program with confidence knowing how big each variable will be.
    >>
    >> Bob.
    >>

    >
    > I repeat:
    > There is NO C compiler that allows you to change the sizes of the
    > basic types. Period.
    >
    > Please show me one C compiler that does that.


    Sun Studio 12. Also 11, 10, 9, and their Forte forbears.

    --
    Eric Sosman
    lid
    Eric Sosman, Sep 6, 2007
    #17
  18. jacob navia wrote:
    > Bob Timpkinson wrote:
    > > Hi,
    > >
    > > I have a 32-bit machine... Is there anyway I can get gcc to use the
    > > following integer sizes?
    > > char: 8 bits
    > > short: 16 bits
    > > int: 32 bits
    > > long: 64 bits
    > > long long: 128 bits
    > >
    > > Thanks!
    > >
    > > Bob.
    > >

    >
    > No way unless:
    > 1) You download the source code of gcc
    > 2) Change quite a few things inside
    >


    Interesting stuff. :) I have the source code of gcc.
    What are the things that can possibly be changed to acheive this ?
    Let me know your ideas . I have thought of giving that a try :):)

    Thx in advans,
    Karthik Balaguru
    karthikbalaguru, Sep 6, 2007
    #18
  19. karthikbalaguru <> writes:
    > jacob navia wrote:
    >> Bob Timpkinson wrote:
    >> > I have a 32-bit machine... Is there anyway I can get gcc to use the
    >> > following integer sizes?
    >> > char: 8 bits
    >> > short: 16 bits
    >> > int: 32 bits
    >> > long: 64 bits
    >> > long long: 128 bits

    >>
    >> No way unless:
    >> 1) You download the source code of gcc
    >> 2) Change quite a few things inside

    >
    > Interesting stuff. :) I have the source code of gcc.
    > What are the things that can possibly be changed to acheive this ?
    > Let me know your ideas . I have thought of giving that a try :):)


    You'll get more and better information in gnu.gcc.help.

    But first, consider why you want to do this, and whether another
    approach might meet your needs.

    If you just want integer types of specified sizes, take a look at the
    <stdint.h> header, which defines int8_t, int16_t, etc.

    --
    Keith Thompson (The_Other_Keith) <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."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
    Keith Thompson, Sep 6, 2007
    #19
  20. [snips]

    On Thu, 06 Sep 2007 11:51:57 -0700, Keith Thompson wrote:

    > If you just want integer types of specified sizes, take a look at the
    > <stdint.h> header, which defines int8_t, int16_t, etc.


    My copy of the draft says that intN_t types are optional, an
    implementation is not required to provide them. As such, it strikes me
    that code cannot rely on them unless one gives up portability across
    compilers, never mind OSen.

    Has this changed, or is this still little more than a good way to
    guarantee you're stuck using one vendor's compiler for the rest of
    eternity?
    Kelsey Bjarnason, Sep 10, 2007
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Fisher

    Integer sizes

    David Fisher, Dec 4, 2003, in forum: C++
    Replies:
    14
    Views:
    876
    Carl Muller
    Dec 10, 2003
  2. Anirudh

    Changing default sizes of data types

    Anirudh, Jul 7, 2004, in forum: C Programming
    Replies:
    3
    Views:
    265
    Malcolm
    Jul 7, 2004
  3. gamehack

    Specific sizes of variable types

    gamehack, Jan 21, 2006, in forum: C Programming
    Replies:
    25
    Views:
    584
    Dave Thompson
    Feb 6, 2006
  4. Replies:
    163
    Views:
    3,245
  5. Ioannis Vranos
    Replies:
    13
    Views:
    486
    James Kanze
    Mar 10, 2008
Loading...

Share This Page