Datatypes

Discussion in 'C Programming' started by anjna22@gmail.com, May 15, 2007.

  1. Guest

    if we simply write "char" or "int" , it is "signed char" or "signed
    int".

    but in some compiler we have to write explicitly "signed int ", why is
    it so.
     
    , May 15, 2007
    #1
    1. Advertising

  2. Ian Collins Guest

    wrote:
    > if we simply write "char" or "int" , it is "signed char" or "signed
    > int".
    >

    No, signed char and char are distinct types.

    > but in some compiler we have to write explicitly "signed int ", why is
    > it so.
    >

    Name one.

    --
    Ian Collins.
     
    Ian Collins, May 15, 2007
    #2
    1. Advertising

  3. In article <>,
    <> wrote:

    >if we simply write "char" or "int" , it is "signed char" or "signed
    >int".
    >
    >but in some compiler we have to write explicitly "signed int ", why is
    >it so.


    No, plain char can be signed or unsigned, but plain int is always
    signed. You might have to write signed char if you want a small
    signed variable, but you never have to write signed int.

    -- Richafrd



    --
    "Consideration shall be given to the need for as many as 32 characters
    in some alphabets" - X3.4, 1963.
     
    Richard Tobin, May 15, 2007
    #3
  4. On May 15, 11:09 am, wrote:
    > if we simply write "char" or "int" , it is "signed char" or "signed
    > int".


    If you write "char", then it will generally have -128 <---> +127, A
    signed char will have all negative values, up to -255. The similar is
    true for int as well.
     
    Keith Halligan, May 15, 2007
    #4
  5. Richard Tobin said:

    > In article <>,
    > <> wrote:
    >
    >>if we simply write "char" or "int" , it is "signed char" or "signed
    >>int".
    >>
    >>but in some compiler we have to write explicitly "signed int ", why is
    >>it so.

    >
    > No, plain char can be signed or unsigned, but plain int is always
    > signed. You might have to write signed char if you want a small
    > signed variable, but you never have to write signed int.


    ....except in bitfields.

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at the above domain, - www.
     
    Richard Heathfield, May 15, 2007
    #5
  6. Keith Halligan said:

    > On May 15, 11:09 am, wrote:
    >> if we simply write "char" or "int" , it is "signed char" or "signed
    >> int".

    >
    > If you write "char", then it will generally have -128 <---> +127,


    Generally, maybe, but not guaranteed.

    On systems where plain char is signed by default (typical PCs), the
    guarantee is -127 to +127. On systems where it is unsigned by default
    (typical mainframes), the guarantee is 0 to 255.

    > A signed char will have all negative values, up to -255.


    On a system where CHAR_BIT is 9, maybe - but of course it must also have
    a corresponding number of positive values and at least one zero value.
    More generally, a signed char will be able to represent all values in
    the range SCHAR_MIN to SCHAR_MAX.

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at the above domain, - www.
     
    Richard Heathfield, May 15, 2007
    #6
  7. Guest

    On May 15, 3:14 pm, Ian Collins <> wrote:
    > wrote:
    > > if we simply write "char" or "int" , it is "signed char" or "signed
    > > int".

    >
    > No, signed char and char are distinct types.
    >
    > > but in some compiler we have to write explicitly "signed int ", why is
    > > it so.

    >
    > Name one.
    >
    > --
    > Ian Collins.


    Can anyone explain difference between char , signed dhar
     
    , May 15, 2007
    #7
  8. said:

    >
    > Can anyone explain difference between char , signed dhar


    signed char, presumably.

    Okay: signed char is a signed integer type, unsigned char is an unsigned
    integer type, and whether char is a signed integer type or an unsigned
    integer type is entirely up to the implementation, but it must document
    its choice.

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at the above domain, - www.
     
    Richard Heathfield, May 15, 2007
    #8
  9. <> schrieb im Newsbeitrag
    news:...
    > On May 15, 3:14 pm, Ian Collins <> wrote:
    >> wrote:
    >> > if we simply write "char" or "int" , it is "signed char" or "signed
    >> > int".

    >>
    >> No, signed char and char are distinct types.
    >>
    >> > but in some compiler we have to write explicitly "signed int ", why is
    >> > it so.

    >>
    >> Name one.
    >>
    >> --
    >> Ian Collins.

    >
    > Can anyone explain difference between char , signed dhar

    char is implementation defined either signed or unsigned, check your
    compiler's documantation
    signed dhar is a typo... OK, just kidding: signed char is just that, at
    least 8 bits wide and signed.
    On some system they are different, on others they are the same.

    Bye, Jojo
     
    Joachim Schmitz, May 15, 2007
    #9
  10. Chris Dollin Guest

    Keith Halligan wrote:

    > On May 15, 11:09 am, wrote:
    >> if we simply write "char" or "int" , it is "signed char" or "signed
    >> int".

    >
    > If you write "char", then it will generally have -128 <---> +127,


    That depends on the implementation. Unmarked char can be represented
    as [note: /not/ the same /type/ as] either signed char or unsigned
    char, at the convenience of the implementation -- which probably
    depends on what its underlying machine does on load-byte instructions.

    > A signed char will have all negative values, up to -255.


    Not on almost all existing machines, it won't, since that would leave
    no room for the C character set, whose elements are positive whatever
    the signedness of char.

    > The similar is true for int as well.


    That depends on what degree of similarity you choose.

    --
    Is it a bird? It is a plane? No, it's: http://hpl.hp.com/conferences/juc2007/
    WARNING. Various parts of this product may be more than one billion years old.

    Hewlett-Packard Limited registered office: Cain Road, Bracknell,
    registered no: 690597 England Berks RG12 1HN
     
    Chris Dollin, May 15, 2007
    #10
  11. Richard Heathfield <> writes:
    > Richard Tobin said:


    >> but you never have to write signed int.

    > ...except in bitfields.


    In my universe, bitfields without 'signed' or 'unsigned' are just as
    signed as any other 'int'.

    mlp
     
    Mark L Pappin, May 15, 2007
    #11
  12. wrote:
    > if we simply write "char" or "int" , it is "signed char" or "signed
    > int".


    Wrong. "int" is indeed a signed int, but unadorned "char" may be either
    a signed char or an unsigned char.

    > but in some compiler we have to write explicitly "signed int ", why is
    > it so.


    Because that compiler is broken.
     
    Martin Ambuhl, May 15, 2007
    #12
  13. Ben Pfaff Guest

    Mark L Pappin <> writes:

    > Richard Heathfield <> writes:
    >> Richard Tobin said:
    >>> but you never have to write signed int.

    >> ...except in bitfields.

    > In my universe, bitfields without 'signed' or 'unsigned' are just as
    > signed as any other 'int'.


    You inhabit a different universe from the rest of us, then.
    From C99 6.7.2:

    ...for bit-fields, it is implementation-defined whether the
    specifier int designates the same type as signed int or the
    same type as unsigned int.

    Similar text is in C90.
    --
    Comp-sci PhD expected before end of 2007
    Seeking industrial or academic position *outside California* in 2008
     
    Ben Pfaff, May 15, 2007
    #13
  14. Keith Halligan wrote:
    > On May 15, 11:09 am, wrote:
    >> if we simply write "char" or "int" , it is "signed char" or "signed
    >> int".

    >
    > If you write "char", then it will generally have -128 <---> +127, A
    > signed char will have all negative values, up to -255. The similar is
    > true for int as well.


    Wrong. If you use unadorned char, it may have a range of at least -127
    to +127, if the implementation treats it as signed _or_ a range of at
    least 0 to 255, if the implementation treats it as unsigned.

    If you write "char" and it is used for any purpose in which values
    outside the range 0 to 127 are possible, then you are living dangerously.
     
    Martin Ambuhl, May 15, 2007
    #14
  15. Mark L Pappin said:

    > Richard Heathfield <> writes:
    >> Richard Tobin said:

    >
    >>> but you never have to write signed int.

    >> ...except in bitfields.

    >
    > In my universe, bitfields without 'signed' or 'unsigned' are just as
    > signed as any other 'int'.


    The Standard disagrees with you, making it clear that this is
    implementation-defined. Several cites are relevant here - here are two,
    one from each Standard:

    C89 3.5.2.1 "A bit-field may have type int , unsigned int , or signed
    int. Whether the high-order bit position of a ``plain'' int bit-field
    is treated as a sign bit is implementation-defined. A bit-field is
    interpreted as an integral type consisting of the specified number of
    bits."

    C99 6.7.2(5) "[...] it is implementation-defined whether the specifier
    int designates the same type as signed int or the same type as unsigned
    int."

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at the above domain, - www.
     
    Richard Heathfield, May 15, 2007
    #15
  16. writes:
    > if we simply write "char" or "int" , it is "signed char" or "signed
    > int".
    >
    > but in some compiler we have to write explicitly "signed int ", why is
    > it so.


    What exactly do you mean by "we have to"? What happens if you write
    "int" rather than "signed int"?

    If they behave differently (other than in a bit field declaration),
    the compiler is broken, but I'd be astonished if any compiler were
    actually broken in that particular way. Can you show examples with
    (short) real code and actual error messages?

    --
    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, May 16, 2007
    #16
  17. Richard Heathfield <> wrote:
    > Mark L Pappin said:
    > > Richard Heathfield <> writes:
    > > > Richard Tobin said:
    > > > > but you never have to write signed int.
    > > >
    > > > ...except in bitfields.

    > >
    > > In my universe, bitfields without 'signed' or
    > > 'unsigned' are just as signed as any other 'int'.

    >
    > The Standard disagrees with you,


    Perhaps he meant _observable_ universe.

    > making it clear that this is implementation-defined.
    > Several cites are relevant here - here are two,
    > one from each Standard:
    >
    > C89 3.5.2.1 "A bit-field may have type int , unsigned
    > int , or signed int. Whether the high-order bit position
    > of a ``plain'' int bit-field is treated as a sign bit is
    > implementation-defined. A bit-field is interpreted as
    > an integral type consisting of the specified number of
    > bits."
    >
    > C99 6.7.2(5) "[...] it is implementation-defined whether
    > the specifier int designates the same type as signed int
    > or the same type as unsigned int."


    The former just means that C89 is backwards compatible
    with K&R C (that didn't have unsigned). The latter just
    means that C99 is backwards compatible with C89.

    Personally, I think it's rediculous that this part is
    preserved, but bitfields are still restricted to a handful
    of integer types. I can't recall ever using a compiler
    that implemented the former or restricted the
    available integer types for bitfields.

    Obviously I haven't turned 60 yet. ;-)

    --
    Peter
     
    Peter Nilsson, May 16, 2007
    #17
  18. Ben Pfaff <> writes:
    > Mark L Pappin <> writes:
    >> Richard Heathfield <> writes:
    >>> Richard Tobin said:
    >>>> but you never have to write signed int.
    >>> ...except in bitfields.

    >> In my universe, bitfields without 'signed' or 'unsigned' are just as
    >> signed as any other 'int'.

    >
    > You inhabit a different universe from the rest of us, then.
    > From C99 6.7.2:

    ....
    > Similar text is in C90.


    My bad. Thanks (and to Richard too) for the references.

    mlp
     
    Mark L Pappin, May 16, 2007
    #18
    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. Guest
    Replies:
    2
    Views:
    563
    Yan-Hong Huang[MSFT]
    Jul 28, 2003
  2. =?Utf-8?B?UGF1cmF2aQ==?=

    Problem while reading excel file with mix datatypes

    =?Utf-8?B?UGF1cmF2aQ==?=, Mar 2, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    603
    Alvin Bruney [MVP]
    Mar 4, 2004
  3. .Net Sports
    Replies:
    1
    Views:
    721
    John Rivers
    Aug 31, 2005
  4. Mark
    Replies:
    2
    Views:
    1,075
  5. Ashish

    complex datatypes in webservices.

    Ashish, Dec 19, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    327
    Joshua Flanagan
    Dec 19, 2005
Loading...

Share This Page