summaryrefslogtreecommitdiffstats
path: root/kdbg/testprogs/anonstruct.cpp
blob: 591a15eef8eae4a1d33ea596eeda9dc20e1888b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// test anonymous structs and unions

#include <cstdio>
#include <pthread.h>

struct T {
	pthread_mutex_t mutex;	// contains anonymous union on Linux
	struct {
		int a;
	};
	union {
		int b;
		long c;
	};
	int TestPopup()
	{
	    return a ? b : c;
	}
};

int main()
{
	pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
	T t;
	union {
		char a;
		int b;
	};
	a = 'X';
	b = t.TestPopup();
	std::fprintf(stderr, "%d, %d, a=%d, b=%d\n", sizeof(mutex), sizeof(t), a, b);
}