unsigned without type (Newbie)

Discussion in 'C Programming' started by Sting, Oct 7, 2003.

  1. Sting

    Sting Guest

    Hello ,
    I have a short simple question:
    what is unsigned without a type?

    like unsigned varname ?

    is it unsigned int, unsigned char ,
    unsigned long,
    etc?
    regards,
    sting
    Sting, Oct 7, 2003
    #1
    1. Advertising

  2. Sting

    Nejat AYDIN Guest

    Sting wrote:
    >
    > Hello ,
    > I have a short simple question:
    > what is unsigned without a type?
    >
    > like unsigned varname ?


    it is equivalent to "unsigned int varname"
    Nejat AYDIN, Oct 7, 2003
    #2
    1. Advertising

  3. On 7 Oct 2003 01:40:58 -0700, (Sting) wrote:

    >like unsigned varname ?
    >
    >is it unsigned int, unsigned char ,
    >unsigned long,


    unsigned varname;

    varname is of type unsigned int. There is no ambiguity. The unsigned
    integer types (C99) are:

    unsigned char var1;
    unsigned short var2;
    unsigned short int var3;
    unsigned long var4;
    unsigned var5;
    unsigned int var6;
    unsigned long int var7;
    unsigned long long var8;
    unsigned long long int var9;

    Note that several types have multiple ways to declare a variable.
    HTH.

    Best wishes,

    Bob
    Robert W Hand, Oct 7, 2003
    #3
  4. Sting

    Richard Bos Guest

    (Sting) wrote:

    > what is unsigned without a type?
    >
    > like unsigned varname ?


    This should be in your C handbook. It certainly is in K&R.

    > is it unsigned int,


    Yes.

    Richard
    Richard Bos, Oct 7, 2003
    #4
  5. Sting

    Dan Pop Guest

    In <> (Sting) writes:

    >I have a short simple question:
    >what is unsigned without a type?
    >
    >like unsigned varname ?
    >
    >is it unsigned int, unsigned char ,
    >unsigned long,
    >etc?


    With the exception of character types, all the integer types
    contain an implied int in their names.
    Here's the complete list of C89 type aliases:

    * short, signed short, short int, or signed short int
    * unsigned short, or unsigned short int
    * int, signed, signed int, or no type specifiers
    * unsigned, or unsigned int
    * long, signed long, long int, or signed long int
    * unsigned long, or unsigned long int

    Dan
    --
    Dan Pop
    DESY Zeuthen, RZ group
    Email:
    Dan Pop, Oct 7, 2003
    #5
  6. Sting

    Jack Klein Guest

    On Tue, 07 Oct 2003 05:27:15 -0400, Robert W Hand
    <> wrote in comp.lang.c:

    > On 7 Oct 2003 01:40:58 -0700, (Sting) wrote:
    >
    > >like unsigned varname ?
    > >
    > >is it unsigned int, unsigned char ,
    > >unsigned long,

    >
    > unsigned varname;
    >
    > varname is of type unsigned int. There is no ambiguity. The unsigned
    > integer types (C99) are:
    >
    > unsigned char var1;
    > unsigned short var2;
    > unsigned short int var3;
    > unsigned long var4;
    > unsigned var5;
    > unsigned int var6;
    > unsigned long int var7;
    > unsigned long long var8;
    > unsigned long long int var9;
    >
    > Note that several types have multiple ways to declare a variable.
    > HTH.
    >
    > Best wishes,
    >
    > Bob


    You forgot one:

    "The type _Bool and the unsigned integer types that correspond to the
    standard signed integer types are the standard unsigned integer
    types."

    6.2.5 paragraph 6.

    _Bool is an unsigned type.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c /faq
    Jack Klein, Oct 8, 2003
    #6
  7. Sting

    Mike Wahler Guest

    "Jack Klein" <> wrote in message
    news:...

    > 6.2.5 paragraph 6.
    >
    > _Bool is an unsigned type.


    .... which leads to the seeming paradox:

    No sign of a _Bool anywhere. :)

    -Mike
    Mike Wahler, Oct 8, 2003
    #7
  8. Sting

    Jack Klein Guest

    On Wed, 08 Oct 2003 19:56:12 GMT, "Mike Wahler"
    <> wrote in comp.lang.c:

    > "Jack Klein" <> wrote in message
    > news:...
    >
    > > 6.2.5 paragraph 6.
    > >
    > > _Bool is an unsigned type.

    >
    > ... which leads to the seeming paradox:
    >
    > No sign of a _Bool anywhere. :)
    >
    > -Mike


    It has some interesting side effects, perhaps not intended by the
    committee, that the C++ bool type does not.

    Consider:

    _Bool /* just plain bool if <stdbool.h> included */ my_bool;

    /* once my_bool is given an initial value... */

    --my_bool;

    ....always toggles from true to false or vice versa.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c /faq
    Jack Klein, Oct 9, 2003
    #8
  9. Sting

    Kevin Bracey Guest

    In message <>
    Jack Klein <> wrote:

    > > > 6.2.5 paragraph 6.
    > > >
    > > > _Bool is an unsigned type.

    >
    > It has some interesting side effects, perhaps not intended by the
    > committee, that the C++ bool type does not.
    >
    > Consider:
    >
    > _Bool /* just plain bool if <stdbool.h> included */ my_bool;
    >
    > /* once my_bool is given an initial value... */
    >
    > --my_bool;
    >
    > ...always toggles from true to false or vice versa.


    Indeed, but that's nothing to do with being an unsigned type, as far as I can
    see. It's just because --x is defined as being equivalent to "(x-=1)".

    That means we calculate the expression "my_bool-1", in which the value of
    my_bool gets promoted to an int, leading to the (int) result -1 or 0. This
    then gets converted back on assignment to the _Bool to 1 and 0 respectively.

    I don't see why C++ outlawed the use of -- on bool myself. Coming from the
    language that decided to use >> for output, it seems a little rich.

    --
    Kevin Bracey, Principal Software Engineer
    Tematic Ltd Tel: +44 (0) 1223 503464
    182-190 Newmarket Road Fax: +44 (0) 1223 503458
    Cambridge, CB5 8HE, United Kingdom WWW: http://www.tematic.com/
    Kevin Bracey, Oct 9, 2003
    #9
    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. Timo Freiberger
    Replies:
    3
    Views:
    930
    Bob Hairgrove
    Oct 30, 2004
  2. George Marsaglia

    Assigning unsigned long to unsigned long long

    George Marsaglia, Jul 8, 2003, in forum: C Programming
    Replies:
    1
    Views:
    658
    Eric Sosman
    Jul 8, 2003
  3. Replies:
    1
    Views:
    441
    Diez B. Roggisch
    Jun 1, 2005
  4. sridhar

    comparing unsigned long and unsigned int

    sridhar, Nov 1, 2004, in forum: C Programming
    Replies:
    6
    Views:
    431
    J. J. Farrell
    Nov 3, 2004
  5. pozz
    Replies:
    12
    Views:
    722
    Tim Rentsch
    Mar 20, 2011
Loading...

Share This Page