Menu - Learn
- Documentation
- Language Reference
- Library Reference
- Command-line Reference
- Feature Overview
- Articles
- Downloads
- Packages
- Community
- Blog
- Orgs using D
- Twitter
- Calendar
- Forums
- IRC
- Wiki
- GitHub
- Issues
- Get involved
- Contributors
- Foundation
- Donate
- Sponsors
- Resources
- Tour
- Books
- Tutorials
- Tools
- Editors
- IDEs
- Visual D
- Acknowledgments
- D Style
- Glossary
- Sitemap
Search Entire Site Language Library ForumsLearn groupThis thread go Forums
Forum Index
- New users
- Community
- Improvements
- Ecosystem
- GDC
- LDC
- Debuggers
- IDEs
- DWT
- Development
- Internals
- Issues
- Beta
- DMD
- Phobos
- Druntime
- Study
- Turkish
Log in Settings HelpIndex » Learn » Behaviour of %08X format specifiers on addresses
| Thread overview |
|---|
| Behaviour of %08X format specifiers on addresses |
|---|
| Sep 22, 2007Graham | | Sep 22, 2007Graham | | Sep 22, 2007Jarrett Billingsley |
|
|
| September 22, 2007Behaviour of %08X format specifiers on addresses |
|---|
 | Posted by Graham | Permalink Reply |
|
Graham Permalink Reply | Being used to printing addresses in "C" as 8 hex digits I though the behavior of this code a little unexpected: import std.stdio; void main(char[][] args) { char* p; int n; p = cast(char*) 1; writefln("p = %08X", p); n = 1; writefln("n = %08X", n); p = cast(char*) 0x12; writefln("p = %08X", p); n = 0x12; writefln("n = %08X", n); p = cast(char*) 0x1234; writefln("p = %08X", p); n = 0x1234; writefln("n = %08X", n); p = cast(char*) 0x123456; writefln("p = %08X", p); n = 0x123456; writefln("n = %08X", n); p = cast(char*) 0x12345678; writefln("p = %08X", p); n = 0x12345678; writefln("n = %08X", n); } which displays: p = 0001 n = 00000001 p = 0012 n = 00000012 p = 1234 n = 00001234 p = 123456 n = 00123456 p = 12345678 n = 12345678 I presume this is intentional (not always displaying the leading zeros on addresses). Is it documented anywhere that this is how it should behave ? I am running the v1.015 compiler on a Windows platform. |
| September 22, 2007Re: Behaviour of %08X format specifiers on addresses |
|---|
 | Posted by Grahamin reply to Graham | Permalink Reply |
|
Graham Posted in reply to Graham Permalink Reply | I realize that the documentation says that the argument should be an integer type when using %X etc. format specifiers, so it works as I expected with writefln("p = %08X", cast(int)p); etc. But even so accepting a non-integer type and then supposing small values are only 16 bits seems a bit odd. |
| September 22, 2007Re: Behaviour of %08X format specifiers on addresses |
|---|
 | Posted by Jarrett Billingsleyin reply to Graham | Permalink Reply |
|
Jarrett Billingsley Posted in reply to Graham Permalink Reply | "Graham" <[email protected]> wrote in message news:fd32ak$255t$1@digitalmars.com... >I realize that the documentation says that the argument should be an integer type when using %X etc. format specifiers, so it works as I expected with > > writefln("p = %08X", cast(int)p); > > etc. > > But even so accepting a non-integer type and then supposing small values are only 16 bits seems a bit odd. Try using writefln("p = %08p", p); It might even just be "%p". |
Top | Forum index | About this forum Copyright © 1999-1980 by the D Language Foundation