Actually the following question prompted this question:
struct addrinfo hints; memset(&hints, 0, sizeof(hints)); //так всё работает //но если memset(&hints, 0, sizeof(addrinfo)); //то почему то возникают проблемы
Now I don’t understand if a variable of type A can occupy more (less) in memory than the size of this type? Example:
struct aaa { ... }; struct aaa var; sizeof(aaa)!=sizeof(var)//можеь ли такое быть? и с чем это связано
And in what cases we have to calculate exactly the size of the MOST variable in memory, and not the size of the TYPE of a variable.
sizeof(struct addrinfo)
(otherwise it just doesn't compile). If you have C andsizeof(addrinfo)
, it means that there is a variable with that name and that is its size you are looking at. Maybe because of this, and errors in the "zeroing". / In my opinion, there is no practical difference betweensizeof(тип)
andsizeof(переменная)
. - avpsizeof(TYPE)
, only to check that some variable ) has the required size (for example, when working with a variable of one type, as if it were a different type). - avp