xref: /minix3/tests/lib/csu/h_initfini_common.cxx (revision 11be35a165022172ed3cea20f2b5df0307540b0e)
1*11be35a1SLionel Sambuc #include <unistd.h>
2*11be35a1SLionel Sambuc 
3*11be35a1SLionel Sambuc #ifdef CHECK_STACK_ALIGNMENT
4*11be35a1SLionel Sambuc #include <stdlib.h>
5*11be35a1SLionel Sambuc 
6*11be35a1SLionel Sambuc extern "C" int check_stack_alignment(void);
7*11be35a1SLionel Sambuc #endif
8*11be35a1SLionel Sambuc 
9*11be35a1SLionel Sambuc class Test {
10*11be35a1SLionel Sambuc public:
Test()11*11be35a1SLionel Sambuc 	Test()
12*11be35a1SLionel Sambuc 	{
13*11be35a1SLionel Sambuc 		static const char msg[] = "constructor executed\n";
14*11be35a1SLionel Sambuc 		write(STDOUT_FILENO, msg, sizeof(msg) - 1);
15*11be35a1SLionel Sambuc #ifdef CHECK_STACK_ALIGNMENT
16*11be35a1SLionel Sambuc 		if (!check_stack_alignment()) {
17*11be35a1SLionel Sambuc 			static const char msg2[] = "stack unaligned \n";
18*11be35a1SLionel Sambuc 			write(STDOUT_FILENO, msg2, sizeof(msg2) - 1);
19*11be35a1SLionel Sambuc 			exit(1);
20*11be35a1SLionel Sambuc 		}
21*11be35a1SLionel Sambuc #endif
22*11be35a1SLionel Sambuc 	}
~Test()23*11be35a1SLionel Sambuc 	~Test()
24*11be35a1SLionel Sambuc 	{
25*11be35a1SLionel Sambuc 		static const char msg[] = "destructor executed\n";
26*11be35a1SLionel Sambuc 		write(STDOUT_FILENO, msg, sizeof(msg) - 1);
27*11be35a1SLionel Sambuc #ifdef CHECK_STACK_ALIGNMENT
28*11be35a1SLionel Sambuc 		if (!check_stack_alignment()) {
29*11be35a1SLionel Sambuc 			static const char msg2[] = "stack unaligned \n";
30*11be35a1SLionel Sambuc 			write(STDOUT_FILENO, msg2, sizeof(msg2) - 1);
31*11be35a1SLionel Sambuc 			exit(1);
32*11be35a1SLionel Sambuc 		}
33*11be35a1SLionel Sambuc #endif
34*11be35a1SLionel Sambuc 	}
35*11be35a1SLionel Sambuc };
36*11be35a1SLionel Sambuc 
37*11be35a1SLionel Sambuc Test test;
38