size_t in c++?

Discussion in 'C++' started by saneman, Aug 1, 2008.

  1. saneman

    saneman Guest

    In a file I have made:

    size_t bb;
    bb = 3u;
    printf("bb %d\n");

    which prints:

    bb 2280640

    But what is 'u' and why does it print the above number?
     
    saneman, Aug 1, 2008
    #1
    1. Advertising

  2. saneman

    Ismo Salonen Guest

    saneman wrote:
    > In a file I have made:
    >
    > size_t bb;
    > bb = 3u;
    > printf("bb %d\n");
    >
    > which prints:
    >
    > bb 2280640
    >
    > But what is 'u' and why does it print the above number?
    >
    >

    Prints garbage from stack, there is no argument given for %d.
    Should be : printf("bb %d\n",bb);

    ismo
     
    Ismo Salonen, Aug 1, 2008
    #2
    1. Advertising

  3. saneman

    Markus Moll Guest

    Hi

    Ismo Salonen wrote:

    > saneman wrote:
    >> In a file I have made:
    >>
    >> size_t bb;
    >> bb = 3u;
    >> printf("bb %d\n");

    >
    > Prints garbage from stack, there is no argument given for %d.
    > Should be : printf("bb %d\n",bb);


    Even then, %d and size_t don't match. Use %zu for size_t, as it might be
    larger than an int.

    Markus
     
    Markus Moll, Aug 1, 2008
    #3
  4. saneman

    Anarki Guest

    On Aug 1, 6:17 pm, Markus Moll <>
    wrote:
    > Hi
    >
    > Ismo Salonen wrote:
    > > saneman wrote:
    > >> In a file I have made:

    >
    > >> size_t bb;
    > >> bb = 3u;
    > >> printf("bb %d\n");

    >
    > > Prints garbage from stack, there is no argument given for %d.
    > > Should be : printf("bb %d\n",bb);

    >
    > Even then, %d and size_t don't match. Use %zu for size_t, as it might be
    > larger than an int.
    >
    > Markus


    excuse me Markus whats %zu? whats the z stand for?
     
    Anarki, Aug 2, 2008
    #4
  5. saneman

    Ian Collins Guest

    Anarki wrote:
    > On Aug 1, 6:17 pm, Markus Moll <>
    > wrote:
    >> Hi
    >>
    >> Ismo Salonen wrote:
    >>> saneman wrote:
    >>>> In a file I have made:
    >>>> size_t bb;
    >>>> bb = 3u;
    >>>> printf("bb %d\n");
    >>> Prints garbage from stack, there is no argument given for %d.
    >>> Should be : printf("bb %d\n",bb);

    >> Even then, %d and size_t don't match. Use %zu for size_t, as it might be
    >> larger than an int.
    >>
    >> Markus

    >
    > excuse me Markus whats %zu? whats the z stand for?


    It's the C99 format specifier for size_t.

    --
    Ian Collins.
     
    Ian Collins, Aug 2, 2008
    #5
    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. Howard Hinnant

    Re: size_t ... standards

    Howard Hinnant, Jun 29, 2003, in forum: C++
    Replies:
    5
    Views:
    3,562
    Jim Fischer
    Jun 30, 2003
  2. Howard Hinnant

    Re: size_t ... standards

    Howard Hinnant, Jun 29, 2003, in forum: C++
    Replies:
    0
    Views:
    843
    Howard Hinnant
    Jun 29, 2003
  3. Chris \( Val \)

    Re: for(size_t a=begin();a!=end();++a){}

    Chris \( Val \), Jul 13, 2003, in forum: C++
    Replies:
    2
    Views:
    351
    John Harrison
    Jul 14, 2003
  4. Alex Vinokur
    Replies:
    9
    Views:
    798
    James Kanze
    Oct 13, 2008
  5. Alex Vinokur
    Replies:
    1
    Views:
    580
Loading...

Share This Page