source: rtems/c/src/tests/samples/cdtest/main.cc @ 7c22114b

4.104.114.84.95
Last change on this file since 7c22114b was ac7d5ef0, checked in by Joel Sherrill <joel.sherrill@…>, on 05/11/95 at 17:39:37

Initial revision

  • Property mode set to 100644
File size: 3.0 KB
Line 
1/*  main
2 *
3 *  This routine is the initialization task for this test program.
4 *  It is called from init_exec and has the responsibility for creating
5 *  and starting the tasks that make up the test.  If the time of day
6 *  clock is required for the test, it should also be set to a known
7 *  value by this function.
8 *
9 *  Input parameters:  NONE
10 *
11 *  Output parameters:  NONE
12 *
13 *  COPYRIGHT (c) 1994 by Division Incorporated
14 *
15 *  Based in part on OAR works.
16 *  To anyone who acknowledges that this file is provided "AS IS"
17 *  without any express or implied warranty:
18 *      permission to use, copy, modify, and distribute this file
19 *      for any purpose is hereby granted without fee, provided that
20 *      the above copyright notice and this notice appears in all
21 *      copies, and that the name of Division Incorporated not be
22 *      used in advertising or publicity pertaining to distribution
23 *      of the software without specific, written prior permission.
24 *      Division Incorporated makes no representations about the
25 *      suitability of this software for any purpose.
26 *
27 *  $Id$
28 */
29
30#include <rtems.h>
31#include <stdio.h>
32#include <libcsupport.h>
33#include <iostream.h>
34
35extern "C" {
36extern rtems_task main_task(rtems_task_argument);
37}
38
39static int num_inst = 0;
40
41class A {
42public:
43    A(void)
44    {
45        num_inst++;
46        printf(
47          "Hey I'm in base class constructor number %d for %p.\n",
48          num_inst,
49          this
50        );
51
52        /*
53         * Make sure we use some space
54         */
55
56        string = new char[50];
57        sprintf(string, "Instantiation order %d", num_inst);
58    };
59
60    virtual ~A()
61    {
62        printf(
63          "Hey I'm in base class destructor number %d for %p.\n",
64          num_inst,
65          this
66        );
67        print();
68        num_inst--;
69    };
70
71    virtual void print()  { printf("%s\n", string); };
72
73protected:
74    char  *string;
75};
76
77class B : public A {
78public:
79    B(void)
80    {
81        num_inst++;
82        printf(
83          "Hey I'm in derived class constructor number %d for %p.\n",
84          num_inst,
85          this
86        );
87
88        /*
89         * Make sure we use some space
90         */
91
92        string = new char[50];
93        sprintf(string, "Instantiation order %d", num_inst);
94    };
95
96    ~B()
97    {
98        printf(
99          "Hey I'm in derived class destructor number %d for %p.\n",
100          num_inst,
101          this
102        );
103              print();
104        num_inst--;
105    };
106
107    void print()  { printf("Derived class - %s\n", string); }
108};
109
110
111A foo;
112B foobar;
113
114void
115cdtest(void)
116{
117    A bar, blech, blah;
118    B bleak;
119
120    cout << "Testing a C++ I/O stream" << endl;
121
122    bar = blech;
123}
124
125//
126// main equivalent
127//      It can not be called 'main' since the bsp owns that name
128//      in many implementations in order to get global constructors
129//      run.
130//
131//      Ref: c/src/lib/libbsp/hppa1_1/simhppa/startup/bspstart.c
132//
133
134
135rtems_task main_task(
136  rtems_task_argument ignored
137)
138{
139    printf( "\n\n*** CONSTRUCTOR/DESTRUCTOR TEST ***\n" );
140
141    cdtest();
142
143    printf( "*** END OF CONSTRUCTOR/DESTRUCTOR TEST ***\n\n\n" );
144
145    exit(0);
146}
Note: See TracBrowser for help on using the repository browser.