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

  • Home
  • SEARCH
  • 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 9180017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:56:39+00:00 2026-06-17T17:56:39+00:00

Compare the codes: const char x = ‘a’; std::cout<< x; 00C31000 mov eax,dword ptr

  • 0

Compare the codes:

    const char x = 'a';
    std::cout<< x;
00C31000  mov         eax,dword ptr [__imp_std::cout (0C32054h)]  
00C31005  push        eax  
00C31006  call        std::operator<<<std::char_traits<char> > (0C310B0h)  
00C3100B  add         esp,4  

and

    const int x = 'a';
    std::cout<< x;
00271000  mov         ecx,dword ptr [__imp_std::cout (272048h)]  
00271006  push        61h  
00271008  call        dword ptr [__imp_std::basic_ostream<char,std::char_traits<char> >::operator<< (272044h)]  

and

    const char* x = "a";
    std::cout<< x;
00071000  mov         eax,dword ptr [__imp_std::cout (72058h)]  
00071005  push        eax  
00071006  call        std::operator<<<std::char_traits<char> > (710B0h)  
0007100B  add         esp,4 

It seems that the const int version is better optimized than the const char* and the (even more surprising)const char version. The question – Why is there a difference in the generated code?

  • 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-06-17T17:56:40+00:00Added an answer on June 17, 2026 at 5:56 pm

    Some overloads of operator<< (including for int, but not char or const char*) are members of std::ostream; some are non-member functions taking std::ostream& as their first parameter.

    Microsoft’s compiler uses different calling conventions for member and non-member functions. I’m guessing that you’re building for 32-bit Windows. In that case member functions will use the thiscall convention, where this is passed in register ecx and the remaining arguments are passed on the stack; and non-member functions use the cdecl convention, where all arguments are passed on the stack.

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

Sidebar

Related Questions

I'm trying to compare a character array against a string like so: const char
#include <string> #include <algorithm> #include <iostream> using namespace std; bool compare( const string::size_type i,
I have a map of pointer to member declared as : std::map<char, T (Operand::*)(const
I'm trying to compare a defined code against a set of blocked country codes.
Suppose we have the following method (it is in c code): const char *bitap_search(const
I am trying to compare std::string s in a locale-dependent manner. For ordinary C-style
What I have: [wstr1] 1 std::wstring value (e.g. (GMT+04:30) Kabul) [str2] 1 char* filled
I have this code: # Compare phone number phone_pattern = '^\d{3} ?\d{3}-\d{4}$' phoneNumber =
What's the best way in code to compare enum values? For example, if I
In my code I need to compare string letters but my problem is that

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.