How to find the size of the structure during programming in the visual studio

I know that the size of the structure is known at compile time, so when programming it should be possible to find the size of the structure. How can i do this?

More specific:

I have a structure:

struct mystruct
{
    int a;
    char b;
    float c[100];
}

I can write this line in my code and run the application and see the size of this structure:

int size=sizeof(mystruct);
cout<<"size is="<<size<<endl;

But this is due to adding a little code to my application and its launch.

Is there a way that the Visual Studio IDE can help me find the size of this structure (for example, by hovering over it and pressing a key!)

+4
source share
5 answers

Intellisense can tell you this. Example:

template <size_t S> class Sizer { };
int x;
Sizer<sizeof(x)> foo;

foo, 4Ui64 - x 4. Ui64 , size_t Unsigned, Integral 64 . Intellisense, . Sizer stdafx.h.

+3

, , - :

template <size_t N> struct helper_size; // undefined.

, -

helper_size<sizeof (mystruct)>::type h;

:

gcc: error: specializing member 'helper_size<408u>::type' requires 'template<>' syntax
visual 2013: error C2027: use of undefined type 'helper_size<408>'

408.

+2

.

jarod:

Native ++

runnning

, . ++ 11 , , :  static-assert-with-sizeof

0

T, :

constexpr size_t sizeOfT = sizeof(T);

sizeOfT, constexpr.

0
source

Source: https://habr.com/ru/post/1548595/


All Articles