Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > size_t in c++?

Reply
Thread Tools

size_t in c++?

 
 
saneman
Guest
Posts: n/a
 
      08-01-2008
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?


 
Reply With Quote
 
 
 
 
Ismo Salonen
Guest
Posts: n/a
 
      08-01-2008
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
 
Reply With Quote
 
 
 
 
Markus Moll
Guest
Posts: n/a
 
      08-01-2008
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

 
Reply With Quote
 
Anarki
Guest
Posts: n/a
 
      08-02-2008
On Aug 1, 6:17*pm, Markus Moll <(E-Mail Removed)>
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?
 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      08-02-2008
Anarki wrote:
> On Aug 1, 6:17 pm, Markus Moll <(E-Mail Removed)>
> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
reinterpret_cast<std::size_t>(p) and reinterpret_cast<std::size_t&>() Alex Vinokur C++ 1 02-06-2011 07:48 AM
Casting from const pair<const unsigned char*, size_t>* to constpair<unsigned char*, size_t>* Alex Vinokur C++ 9 10-13-2008 05:05 PM
Re: for(size_t a=begin();a!=end();++a){} Chris \( Val \) C++ 2 07-14-2003 06:31 AM
Re: size_t ... standards Howard Hinnant C++ 5 06-30-2003 07:22 PM
Re: size_t ... standards Howard Hinnant C++ 0 06-29-2003 05:45 PM



Advertisments