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

4.104.114.84.95
Last change on this file since e71ce071 was e71ce071, checked in by Joel Sherrill <joel.sherrill@…>, on Apr 22, 1997 at 5:47:16 PM

updated with new license information per Tony Bennett.

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