Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / October 2007

Tip: Looking for answers? Try searching our database.

Printf %d and %ld

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
George - 24 Oct 2007 10:17 GMT
Hello everyone,

I think printf %d works fine with signed, unsigned and negative integer
values, and the same as %ld for long. Is that correct? If not, do we need to
special conversion?

thanks in advance,
George
David Wilkinson - 24 Oct 2007 10:59 GMT
> Hello everyone,
>
> I think printf %d works fine with signed, unsigned and negative integer
> values, and the same as %ld for long. Is that correct? If not, do we need to
> special conversion?

George:

%d will only work for unsigned int if the value is not bigger than the
largest allowed value of int. Otherwise, a negative value will be displayed.

Signature

David Wilkinson
Visual C++ MVP

George - 24 Oct 2007 11:16 GMT
Hi David,

Only works for unsigned int? I have tried that -1 works. :-)

int i = -1;
printf ("i is: %d", -1);

I have tried it on Visual Studio 2005.

regards,
George

> > Hello everyone,
> >
[quoted text clipped - 6 lines]
> %d will only work for unsigned int if the value is not bigger than the
> largest allowed value of int. Otherwise, a negative value will be displayed.
David Wilkinson - 24 Oct 2007 13:43 GMT
> Hi David,
>
[quoted text clipped - 10 lines]
>> %d will only work for unsigned int if the value is not bigger than the
>> largest allowed value of int. Otherwise, a negative value will be displayed.

George:

I meant:

For unsigned int, %d will only work if the value is not bigger than the
largest allowed value of int. Otherwise, a negative value will be
displayed. %u should be used with unsigned int.

%d is intended for use with int, and either positive or negative values
may be displayed.

Although not so well suited to localization, C++ streams handle this
issue much better, because they are overloaded for different types.

Signature

David Wilkinson
Visual C++ MVP

George - 25 Oct 2007 09:54 GMT
Thanks David,

I agree.

regards,
George

> > Hi David,
> >
[quoted text clipped - 24 lines]
> Although not so well suited to localization, C++ streams handle this
> issue much better, because they are overloaded for different types.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.