Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

behaviour of tiny c++ structs

Tags:

c++

struct

If I define a struct like:

struct tiny
{
    long t;
};

will it be handled like a long in terms of function arguments and alike, in example would the parameter of:

void myfunc(tiny x)
{ ... }

be handled like a long parameter by actually being pushed on the stack?

So essentially, is the tiny struct only as large as a its sole member?

Thanks

like image 543
litro Avatar asked Mar 04 '11 17:03

litro


1 Answers

The memory consumption of a structure is at least the sum of the memory sizes of constituent variables.

However, the compiler may add padding between the variables or at the end of the structure to ensure proper data alignment for a given computer architecture

like image 189
Aviv A. Avatar answered Sep 28 '22 17:09

Aviv A.