An implementation where sizeof(short int) does not divide sizeof(int)

Discussion in 'C Programming' started by Spiros Bousbouras, Jan 15, 2007.

  1. Do you have an example of an implementation where
    sizeof(short int) does not divide sizeof(int) or
    sizeof(int) does not divide sizeof(long int) or
    sizeof(long int) does not divide sizeof(long long int) ?

    Same question for the corresponding unsigned types.
     
    Spiros Bousbouras, Jan 15, 2007
    #1
    1. Advertising

  2. Spiros Bousbouras wrote:
    > Do you have an example of an implementation where
    > sizeof(short int) does not divide sizeof(int) or
    > sizeof(int) does not divide sizeof(long int) or
    > sizeof(long int) does not divide sizeof(long long int) ?
    >
    > Same question for the corresponding unsigned types.


    What about...

    An implementation where long has 40 value bits... (TI DSPs)
    An implementation where sizeof (long double) == 10 or == 12... (IEEE
    754 Standard)
     
    christian.bau, Jan 15, 2007
    #2
    1. Advertising

  3. "Spiros Bousbouras" <> wrote in message
    news:...
    > Do you have an example of an implementation where
    > sizeof(short int) does not divide sizeof(int) or
    > sizeof(int) does not divide sizeof(long int) or
    > sizeof(long int) does not divide sizeof(long long int) ?
    >
    > Same question for the corresponding unsigned types.


    Interesting question, but probably irrelevant to actual programming.

    It is an accident of computer evolution that the relationships you are
    seeking an exception to exist. I have no idea why in the world one can't
    easily find a computer with 40-bit integers or 48-bit integers, for example.

    Counteroffer: can you show me a poor 'C' implementation that will fail if
    the relationships you mention don't hold? I've never seen that, either.

    --
    David T. Ashley ()
    http://www.e3ft.com (Consulting Home Page)
    http://www.dtashley.com (Personal Home Page)
    http://gpl.e3ft.com (GPL Publications and Projects)
     
    David T. Ashley, Jan 16, 2007
    #3
  4. Spiros Bousbouras wrote:
    > Do you have an example of an implementation where
    > sizeof(short int) does not divide sizeof(int) or
    > sizeof(int) does not divide sizeof(long int) or
    > sizeof(long int) does not divide sizeof(long long int) ?


    No, but I have used two where sizeof(int) does not divide
    sizeof(double) [4 and 10 respectively.]

    > Same question for the corresponding unsigned types.


    Yes, it is the same question. The size of a signed integer
    is necessarily the same as the size of the corresponding
    unsigned type.

    But why are you concerned about size? It's a common
    misconception that size is more important than value.
    [Read that any way you want.] Another popular
    misconception is that _where_ an object is located is
    more important than _when_ it exists.

    --
    Peter
     
    Peter Nilsson, Jan 16, 2007
    #4
  5. Spiros Bousbouras

    user923005 Guest

    Spiros Bousbouras wrote:
    > Do you have an example of an implementation where
    > sizeof(short int) does not divide sizeof(int) or
    > sizeof(int) does not divide sizeof(long int) or
    > sizeof(long int) does not divide sizeof(long long int) ?
    >
    > Same question for the corresponding unsigned types.


    How about where sizeof int is not evenly divisible by sizeof char?
    CDC Cyber UTexas C compiler

    60 bits is not divisible by 8. They stored characters two words at a
    time though, so you had 120 bits, which is divisible by 8.

    IIRC.
     
    user923005, Jan 16, 2007
    #5
  6. Spiros Bousbouras

    Ben Pfaff Guest

    "user923005" <> writes:

    > Spiros Bousbouras wrote:
    >> Do you have an example of an implementation where
    >> sizeof(short int) does not divide sizeof(int) or
    >> sizeof(int) does not divide sizeof(long int) or
    >> sizeof(long int) does not divide sizeof(long long int) ?
    >>
    >> Same question for the corresponding unsigned types.

    >
    > How about where sizeof int is not evenly divisible by sizeof char?
    > CDC Cyber UTexas C compiler


    I don't think non-ANSI implementations are on-topic here.
    --
    Ben Pfaff
    email:
    web: http://benpfaff.org
     
    Ben Pfaff, Jan 16, 2007
    #6
  7. In article <> "David T. Ashley" <> writes:
    > "Spiros Bousbouras" <> wrote in message
    > news:...
    > > Do you have an example of an implementation where
    > > sizeof(short int) does not divide sizeof(int) or
    > > sizeof(int) does not divide sizeof(long int) or
    > > sizeof(long int) does not divide sizeof(long long int) ?
    > >
    > > Same question for the corresponding unsigned types.

    >
    > Interesting question, but probably irrelevant to actual programming.


    Indeed, not very interesting. But something like that happened on
    the Cray-1. I disremember whether a short was 24 or 32 bits. But
    there was a compiler flag that said that ints were either 48 or 64
    bits, but the size of a short was fixed. I think the base mode was
    shorts of 24 bits and ints of 48 bits and the extravaganza mode was
    shorts of 24 bits and ints of 64 bits.
    --
    dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
    home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
     
    Dik T. Winter, Jan 16, 2007
    #7
  8. Spiros Bousbouras

    Rudolf Guest

    In article <>,
    "user923005" <> wrote:

    >
    > How about where sizeof int is not evenly divisible by sizeof char?
    > CDC Cyber UTexas C compiler



    sizeof char is 1. How is anything not evenly divisible by one?

    --
    Posted via a free Usenet account from http://www.teranews.com
     
    Rudolf, Jan 16, 2007
    #8
  9. Spiros Bousbouras

    Old Wolf Guest

    user923005 wrote:
    > How about where sizeof int is not evenly divisible by sizeof char?


    sizeof(char) is always 1, so this is not possible.

    > CDC Cyber UTexas C compiler
    >
    > 60 bits is not divisible by 8. They stored characters two words at a
    > time though, so you had 120 bits, which is divisible by 8.


    "sizeof" gives the size in bytes, not in bits.
     
    Old Wolf, Jan 16, 2007
    #9
  10. In article <> "user923005" <> writes:
    > Spiros Bousbouras wrote:
    > > Do you have an example of an implementation where
    > > sizeof(short int) does not divide sizeof(int) or
    > > sizeof(int) does not divide sizeof(long int) or
    > > sizeof(long int) does not divide sizeof(long long int) ?
    > >
    > > Same question for the corresponding unsigned types.

    >
    > How about where sizeof int is not evenly divisible by sizeof char?
    > CDC Cyber UTexas C compiler


    That would violate the standard. sizeof is expressed as an integral
    unit, where sizeof char == 1. And that was already true in K&R.

    > 60 bits is not divisible by 8. They stored characters two words at a
    > time though, so you had 120 bits, which is divisible by 8.


    That is possible (but gives problems with floats that are also 60 bits).
    But on those machines it is much more reasonable to have 48 bit ints
    with the remaining 16 bits (possible) garbage. But integer arithmetic
    on those machines had quite a few strange points. That is, I could
    easily construct examples where:
    (a + a) * 2 != a + a + a + a
    in integer arithmetic, even when a < 2**48.
    --
    dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
    home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
     
    Dik T. Winter, Jan 16, 2007
    #10
  11. Spiros Bousbouras

    user923005 Guest

    Dik T. Winter wrote:
    > In article <> "user923005" <> writes:
    > > Spiros Bousbouras wrote:
    > > > Do you have an example of an implementation where
    > > > sizeof(short int) does not divide sizeof(int) or
    > > > sizeof(int) does not divide sizeof(long int) or
    > > > sizeof(long int) does not divide sizeof(long long int) ?
    > > >
    > > > Same question for the corresponding unsigned types.

    > >
    > > How about where sizeof int is not evenly divisible by sizeof char?
    > > CDC Cyber UTexas C compiler

    >
    > That would violate the standard. sizeof is expressed as an integral
    > unit, where sizeof char == 1. And that was already true in K&R.


    I wonder if it was written between 1969 (~ eariliest origins of C) and
    1978 (K&R I published), in which case K&R I does not apply.

    Some of the C compilers I used around 1984-1986 were at extreme
    opposition. As I recall, Lattice C, Manx C, Microsoft C (and some
    other which I forget) were so dissimilar that it was often easier to
    write separate source files instead of using #ifdef
    COMPILER_SPECIFIC_FLAG #endif around the compiler specific stuff.
     
    user923005, Jan 16, 2007
    #11
  12. In article <> "user923005" <> writes:
    > Dik T. Winter wrote:
    > > In article <> "user923005" <> writes:

    ....
    > > > How about where sizeof int is not evenly divisible by sizeof char?
    > > > CDC Cyber UTexas C compiler

    > >
    > > That would violate the standard. sizeof is expressed as an integral
    > > unit, where sizeof char == 1. And that was already true in K&R.

    >
    > I wonder if it was written between 1969 (~ eariliest origins of C) and
    > 1978 (K&R I published), in which case K&R I does not apply.


    We shifted to a CDC Cyber around 1976, or perhaps earlier. The first time
    I even heard about the UTexas C compiler was about 10 years later. That was
    when the computing centre asked us whether it should be available as a
    standard compiler kit, I do not think it was much older. My answer to
    the question was: *no*. The reason was that it was not suitable for
    interactive work (the compiler required too much memory). And it never
    was made available. BTW, at that time we had an Algol 68 compiler that
    did nearly everything of Algol 68 in interactive sessions. But as far
    as that C compiler was concerned, that is just what I did look at. And
    we had already quite a few PDP's running, *with* C compilers, so C on
    the mainframe without the possibility to do it interactive was out of
    the question.

    > As I recall, Lattice C, Manx C, Microsoft C (and some
    > other which I forget) were so dissimilar that it was often easier to
    > write separate source files instead of using #ifdef
    > COMPILER_SPECIFIC_FLAG #endif around the compiler specific stuff.


    Possibly true. They all implemented dialects of C, and also had all
    their idiosyncrastic bugs. I have still some source files around
    really littered with #ifdef and #endif statements. But, they still
    do compile. (That is a program I ported to about 40 different
    compiler/OS combos.)
    --
    dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
    home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
     
    Dik T. Winter, Jan 16, 2007
    #12
  13. Spiros Bousbouras

    Ben Pfaff Guest

    "Dik T. Winter" <> writes:

    > We shifted to a CDC Cyber around 1976, or perhaps earlier. The first time
    > I even heard about the UTexas C compiler was about 10 years later. That was
    > when the computing centre asked us whether it should be available as a
    > standard compiler kit, I do not think it was much older. My answer to
    > the question was: *no*. The reason was that it was not suitable for
    > interactive work (the compiler required too much memory).
    > [...]


    Out of curiosity: how much memory was considered too much for a
    compiler to consume on that machine at the time?
    --
    "I don't have C&V for that handy, but I've got Dan Pop."
    --E. Gibbons
     
    Ben Pfaff, Jan 16, 2007
    #13
  14. Spiros Bousbouras

    CBFalconer Guest

    Re: An implementation where sizeof(short int) does not dividesizeof(int)

    user923005 wrote:
    > Spiros Bousbouras wrote:
    >
    >> Do you have an example of an implementation where
    >> sizeof(short int) does not divide sizeof(int) or
    >> sizeof(int) does not divide sizeof(long int) or
    >> sizeof(long int) does not divide sizeof(long long int) ?
    >>
    >> Same question for the corresponding unsigned types.

    >
    > How about where sizeof int is not evenly divisible by sizeof char?
    > CDC Cyber UTexas C compiler


    Impossible on the face of it. Anything is divisible by one.

    > 60 bits is not divisible by 8. They stored characters two words at a
    > time though, so you had 120 bits, which is divisible by 8.


    I suspect you are confusing CHAR_BIT with sizeof char.

    --
    "A man who is right every time is not likely to do very much."
    -- Francis Crick, co-discover of DNA
    "There is nothing more amazing than stupidity in action."
    -- Thomas Matthews
    <http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
     
    CBFalconer, Jan 16, 2007
    #14
  15. Spiros Bousbouras

    user923005 Guest

    Ben Pfaff wrote:
    > "user923005" <> writes:
    >
    > > Spiros Bousbouras wrote:
    > >> Do you have an example of an implementation where
    > >> sizeof(short int) does not divide sizeof(int) or
    > >> sizeof(int) does not divide sizeof(long int) or
    > >> sizeof(long int) does not divide sizeof(long long int) ?
    > >>
    > >> Same question for the corresponding unsigned types.

    > >
    > > How about where sizeof int is not evenly divisible by sizeof char?
    > > CDC Cyber UTexas C compiler

    >
    > I don't think non-ANSI implementations are on-topic here.


    Perhaps, but if that is the case then what is topical has drifted. For
    example:

    "From: Lawrence Kirby - view profile
    Date: Wed, Jul 29 1998 11:00 pm
    Email: (Lawrence Kirby)
    Groups: comp.lang.c

    In article <01bdbb71$0ab255c0$47112599@exnoop1>
    "Bruce Henderson" writes:
    ....

    >The topic here is "C". Not ANSI C just C.


    Lets be perfectly clear about this. comp.lang.c is a newsgroup for
    discussinbg the C programming language. The C programming language
    is currently defined by the ISO 9899-1990 standard (plus a few minor
    amendments). That hasn't always been the case and it is reasonable to
    discuss historical forms of the language (such as "K&R C") here as long

    as that is clear in the article."

    {remainder snipped}

    > --
    > Ben Pfaff
    > email:
    > web: http://benpfaff.org
     
    user923005, Jan 16, 2007
    #15
  16. Spiros Bousbouras

    user923005 Guest

    Ben Pfaff wrote:
    [snip]
    > Out of curiosity: how much memory was considered too much for a
    > compiler to consume on that machine at the time?


    {not related to the CDC Cyber, but of the same period...}
    In 1976, I worked on an IBM 360 at Patrick AFB in Florida.
    Any job that consumed more than 200K required special permission,
    granted by an officer.
    I remember well, because I had to run a job that required 276K at least
    once every day.

    > --
    > "I don't have C&V for that handy, but I've got Dan Pop."
    > --E. Gibbons
     
    user923005, Jan 16, 2007
    #16
  17. Spiros Bousbouras

    Ben Pfaff Guest

    "user923005" <> writes:

    > Ben Pfaff wrote:
    >> "user923005" <> writes:
    >>
    >> > Spiros Bousbouras wrote:
    >> >> Do you have an example of an implementation where
    >> >> sizeof(short int) does not divide sizeof(int) or
    >> >> sizeof(int) does not divide sizeof(long int) or
    >> >> sizeof(long int) does not divide sizeof(long long int) ?
    >> >>
    >> >> Same question for the corresponding unsigned types.
    >> >
    >> > How about where sizeof int is not evenly divisible by sizeof char?
    >> > CDC Cyber UTexas C compiler

    >>
    >> I don't think non-ANSI implementations are on-topic here.

    >
    > Perhaps, but if that is the case then what is topical has
    > drifted. [...]


    Indeed. Let me state my objection better, then:

    The CDC Cyber UTexas C compiler must not have been an ANSI C
    compiler, because that situation can't happen in ANSI C. I
    suspect that the OP is looking for current compilers, not ancient
    and obsolete ones.

    (It's a fascinating fact in any case.)
    --
    "In My Egotistical Opinion, most people's C programs should be indented six
    feet downward and covered with dirt." -- Blair P. Houghton
     
    Ben Pfaff, Jan 16, 2007
    #17
  18. Spiros Bousbouras

    user923005 Guest

    Ben Pfaff wrote:
    > "user923005" <> writes:
    >
    > > Ben Pfaff wrote:
    > >> "user923005" <> writes:
    > >>
    > >> > Spiros Bousbouras wrote:
    > >> >> Do you have an example of an implementation where
    > >> >> sizeof(short int) does not divide sizeof(int) or
    > >> >> sizeof(int) does not divide sizeof(long int) or
    > >> >> sizeof(long int) does not divide sizeof(long long int) ?
    > >> >>
    > >> >> Same question for the corresponding unsigned types.
    > >> >
    > >> > How about where sizeof int is not evenly divisible by sizeof char?
    > >> > CDC Cyber UTexas C compiler
    > >>
    > >> I don't think non-ANSI implementations are on-topic here.

    > >
    > > Perhaps, but if that is the case then what is topical has
    > > drifted. [...]

    >
    > Indeed. Let me state my objection better, then:
    >
    > The CDC Cyber UTexas C compiler must not have been an ANSI C
    > compiler, because that situation can't happen in ANSI C. I
    > suspect that the OP is looking for current compilers, not ancient
    > and obsolete ones.


    I might be misremembering in any case, because we never actually got it
    to work and just stuck with FORTRAN anyway. The FORTRAN compiler also
    had really weird operations to pack and unpack character strings from
    words. I doubt that the FORTRAN compiler for that machine met F77
    standards.

    > (It's a fascinating fact in any case.)
    > --
    > "In My Egotistical Opinion, most people's C programs should be indented six
    > feet downward and covered with dirt." -- Blair P. Houghton
     
    user923005, Jan 16, 2007
    #18
  19. Spiros Bousbouras

    user923005 Guest

    CBFalconer wrote:
    > user923005 wrote:
    > > Spiros Bousbouras wrote:
    > >
    > >> Do you have an example of an implementation where
    > >> sizeof(short int) does not divide sizeof(int) or
    > >> sizeof(int) does not divide sizeof(long int) or
    > >> sizeof(long int) does not divide sizeof(long long int) ?
    > >>
    > >> Same question for the corresponding unsigned types.

    > >
    > > How about where sizeof int is not evenly divisible by sizeof char?
    > > CDC Cyber UTexas C compiler

    >
    > Impossible on the face of it. Anything is divisible by one.


    Hard to argue with that.

    > > 60 bits is not divisible by 8. They stored characters two words at a
    > > time though, so you had 120 bits, which is divisible by 8.

    >
    > I suspect you are confusing CHAR_BIT with sizeof char.


    Ummm... What he said.

    > --
    > "A man who is right every time is not likely to do very much."
    > -- Francis Crick, co-discover of DNA
    > "There is nothing more amazing than stupidity in action."
    > -- Thomas Matthews
    > <http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
     
    user923005, Jan 16, 2007
    #19
  20. Re: An implementation where sizeof(short int) does not dividesizeof(int)

    "user923005" <> writes:
    > Spiros Bousbouras wrote:
    >> Do you have an example of an implementation where
    >> sizeof(short int) does not divide sizeof(int) or
    >> sizeof(int) does not divide sizeof(long int) or
    >> sizeof(long int) does not divide sizeof(long long int) ?
    >>
    >> Same question for the corresponding unsigned types.

    >
    > How about where sizeof int is not evenly divisible by sizeof char?
    > CDC Cyber UTexas C compiler
    >
    > 60 bits is not divisible by 8. They stored characters two words at a
    > time though, so you had 120 bits, which is divisible by 8.


    sizeof(int) is divisible by sizeof(char) in any conforming C
    implementation; sizeof(char) is 1 by definition.

    Implementing C on a system with 8-bit characters and 60-bit integers
    would be, um, interesting.

    --
    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.
     
    Keith Thompson, Jan 16, 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. Derek
    Replies:
    7
    Views:
    24,371
    Ron Natalie
    Oct 14, 2004
  2. blufox

    sizeof( int ) != sizeof( void * )

    blufox, May 22, 2006, in forum: C Programming
    Replies:
    2
    Views:
    567
    Joe Smith
    May 22, 2006
  3. Steve Hicks
    Replies:
    2
    Views:
    1,278
  4. Stargazer

    Re: sizeof(const int *) > sizeof(int *)

    Stargazer, Jun 14, 2010, in forum: C Programming
    Replies:
    14
    Views:
    681
    Ben Bacarisse
    Jul 8, 2010
  5. Ben Bacarisse

    Re: sizeof(const int *) > sizeof(int *)

    Ben Bacarisse, Jun 14, 2010, in forum: C Programming
    Replies:
    12
    Views:
    440
    David Thompson
    Jul 2, 2010
Loading...

Share This Page