Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 936763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:21:57+00:00 2026-05-15T21:21:57+00:00

PSPS: (a Pre-scripted Post-script) It has just come to mind that a more prescient

  • 0

PSPS: (a Pre-scripted Post-script)
It has just come to mind that a more prescient question would have included the notion of: Is this non-display of “0x”(showbase) for zero-value integers a standard behaviour, or is it just a quirk of my MinGW implementation?

It all began on a pleasant Sunday morning… I want to dump some Handles in their hex representation, and in a consistant, formatted way.
I want a leading 0x and a fixed width, but this is proving to be elusive using the expected stream manipulators.
The only way I’ve found to do this is to cast the Handles to an unsigned long.
This seems a bit unreasonable, and I would expect that I’m not the only person to have ever wanted this..
Am I missing something in the standard hex manipulators? Is it because type void* (HANDLE) is simply defined outside of the normal hex-handling of ostream?

In summary: I don’t want to have to cast HANDLE to something which it isn’t.
and I don’t want to hard code a “0x” prefix. Is there a way to do it using standard manipulators? or would I need to overload ostream’s handling of HANDLE? (but that might overload me!)

Here is my test code (and its output).
I’ve used ‘.’ as the fill char, for clarity, (I will actually be using ‘0’)

HANDLE h; 
ULONG ul; 
int iH = sizeof(h); // how many bytes to this void* type.
int iW = iH*2;      // the max number of hex digits (width).
int iW2= iW+2;      // the max number of hex digits (+ 2 for showbase "0x").
int iX = 4;         // the number of bits per hex digit.
int ib = iH*8;      // the max number bits in HANDLE (exponent).
int i;
std::cout<<std::setfill('.'); // I actually want '0'; 
                              //   the dot is for display clarity
for( i=0; i<=ib; i+=iX )
{ ul = (pow(2,i)-1);
  h  = (HANDLE)ul;
  std::cout
  <<"//  ul "        <<std::setw(iW2)<<std::hex <<std::showbase  <<std::internal <<ul
  <<"     h "        <<std::setw(iW2) /* hex,showbase,internal have no effect */ <<h
  <<"      I want 0x"<<std::setw(iW) <<std::hex <<std::noshowbase<<std::right    <<(ULONG)h
  <<std::endl;
}

//  ul .........0     h .........0      I want 0x.......0
//  ul 0x.......f     h .......0xf      I want 0x.......f
//  ul 0x......ff     h ......0xff      I want 0x......ff
//  ul 0x.....fff     h .....0xfff      I want 0x.....fff
//  ul 0x....ffff     h ....0xffff      I want 0x....ffff
//  ul 0x...fffff     h ...0xfffff      I want 0x...fffff
//  ul 0x..ffffff     h ..0xffffff      I want 0x..ffffff
//  ul 0x.fffffff     h .0xfffffff      I want 0x.fffffff
//  ul 0xffffffff     h 0xffffffff      I want 0xffffffff
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T21:21:57+00:00Added an answer on May 15, 2026 at 9:21 pm

    I found this on https://bugzilla.redhat.com/show_bug.cgi?id=166735 – this is copy/paste straight from there.

    Doesn’t sound like a bug to me.
    ISO C++98, 22.2.2.2.2/10 says std::showbase means prepending # printf conversion
    qualifier. 22.2.2.2.2/7 says std::hex means the printf conversion specifier is
    %x.
    So the behaviour is IMHO required to be the same as printf (“%#x”, 0);
    But http://www.opengroup.org/onlinepubs/009695399/functions/fprintf.html
    says:
    “For x or X conversion specifiers, a non-zero result shall have 0x (or 0X)
    prefixed to it.”
    The same is in ISO C99, 7.19.6.1(6):
    “For x (or X) conversion, a nonzero result has 0x (or 0X) prefixed to it.”

    So it sounds like the C++98 standard (by saying ‘make it like C’s printf(“%#x”, 0)’) requires this goofy behavior you’re seeing. The only way to get what you want would be to get rid of the std::showbase and output 0x explicitly. Sorry.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's have a class Person . Person has a name and height. Equals and
I have a second resx file Strings.ps-ps.resx that I want to point my code
I have a problem with free() function in C linux. here is my sample
I'm using SlimDX, targeting DirectX 11 with shader model 4. I have a pixel
I'm trying to make a program that counts the number of lines of a
I have to write fast right-trimming function in C. My first attempt to do
I am a beginner in using autotool, I want to add some shell script
How can I access myobject[path][to][obj] via a string path.to.obj ? I want to call
I've been banging my head against a wall for a few hours now -
I try to load image with processing.js using CoffeeScript and write this simple code:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.