When I have sizeof(utmp) , 384 is returned. So when I try to find out the size of the individual members, I get a different result. Using the method below, I come up with 382 bytes. Anyone know where I'm missing the other 2 bytes?

#include <iostream>
using std::cout;
using std::endl;

#include <utmp.h>

void size();

int main()
{
	size();
	return 0;
}

void size()
{
	utmp uLine;
	cout << "ut_type: " << sizeof(uLine.ut_type) << " bytes." << endl;
	cout << "ut_pid: " << sizeof(uLine.ut_pid) << " bytes." << endl;
	cout << "ut_line: " << sizeof(uLine.ut_line) << " bytes." << endl;
	cout << "ut_id: " << sizeof(uLine.ut_id) << " bytes." << endl;
	cout << "ut_user: " << sizeof(uLine.ut_user) << " bytes." << endl;
	cout << "ut_host: " << sizeof(uLine.ut_host) << " bytes." << endl;
	cout << "ut_session: " << sizeof(uLine.ut_session) << " bytes." << endl;
	cout << "ut_tv: " << sizeof(uLine.ut_tv) << " bytes." << endl;
	cout << "ut_addr_v6: " << sizeof(uLine.ut_addr_v6) << " bytes." << endl;
	cout << "ut_exit: " << sizeof(uLine.ut_exit) << " bytes." << endl;
	cout << "ut__unused: " << sizeof(uLine.__unused) << " bytes." << endl;
}

Recommended Answers

All 2 Replies

Just a guess, don't take this as gospel, but possibly the compiler is setting aside 384 bytes since 384 is a multiple of 4 and 382 isn't and for efficiency purposes, in a 32 bit system, the compiler only delegates memory in multiples of 4 bytes (4 bytes = 32 bits) for more efficient address calculation.

That's just one compiler novice's semi-educated guess.

Oh! That makes sense, that didn't even occur to me. Sounds good to me, thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.