Our website uses cookies to enhance your browsing experience.
Accept
to the top
close form

Fill out the form in 2 simple steps below:

Your contact information:

Step 1
Congratulations! This is your promo code!

Desired license type:

Step 2
Team license
Enterprise license
** By clicking this button you agree to our Privacy Policy statement
close form
Request our prices
New License
License Renewal
--Select currency--
USD
EUR
* By clicking this button you agree to our Privacy Policy statement

close form
Free PVS‑Studio license for Microsoft MVP specialists
* By clicking this button you agree to our Privacy Policy statement

close form
To get the licence for your open-source project, please fill out this form
* By clicking this button you agree to our Privacy Policy statement

close form
I am interested to try it on the platforms:
* By clicking this button you agree to our Privacy Policy statement

close form
check circle
Message submitted.

Your message has been sent. We will email you at


If you do not see the email in your inbox, please check if it is filtered to one of the following folders:

  • Promotion
  • Updates
  • Spam

Webinar: Evaluation - 05.12

>
>
>
The function of printing an expression'…

The function of printing an expression's type

Jul 20 2009
Author:

I very often meet debates in forums on what type this or that expression will have. So I decided to make a little note in the blog to refer to this.

An example of code printing the type of an expression and information about it:

#include <iostream>
using namespace std;
template <typename T>
void PrintTypeInfo(char const* description, T)
{
  const type_info &info = typeid(T);
  cerr << "\"" << description << "\":"
       << " type = " << info.name()
       << "; sizeof = " << sizeof (T)
       << "; alignof = " << __alignof (T)
       << endl;
}
int _tmain(int, _TCHAR *[])
{
  char c1 = 0, c2 = 0;
  PrintTypeInfo("char + char", c1 + c2);
}

The result:

"char + char": type = int; sizeof = 4; alignof = 4


Comments (0)

Next comments next comments
close comment form