source: rtems/testsuites/samples/cdtest/main.cc @ 11290355

4.104.114.84.95
Last change on this file since 11290355 was 11290355, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 29, 1995 at 5:19:16 PM

all targets compile .. tony's patches in place

  • 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 <iostream.h>
33
34extern "C" {
35extern rtems_task main_task(rtems_task_argument);
36}
37
38static int num_inst = 0;
39
40class A {
41public:
42    A(void)
43    {
44        num_inst++;
45        printf(
46          "Hey I'm in base class constructor number %d for %p.\n",
47          num_inst,
48          this
49        );
50
51        /*
52         * Make sure we use some space
53         */
54
55        string = new char[50];
56        sprintf(string, "Instantiation order %d", num_inst);
57    };
58
59    virtual ~A()
60    {
61        printf(
62          "Hey I'm in base class destructor number %d for %p.\n",
63          num_inst,
64          this
65        );
66        print();
67        num_inst--;
68    };
69
70    virtual void print()  { printf("%s\n", string); };
71
72protected:
73    char  *string;
74};
75
76class B : public A {
77public:
78    B(void)
79    {
80        num_inst++;
81        printf(
82          "Hey I'm in derived class constructor number %d for %p.\n",
83          num_inst,
84          this
85        );
86
87        /*
88         * Make sure we use some space
89         */
90
91        string = new char[50];
92        sprintf(string, "Instantiation order %d", num_inst);
93    };
94
95    ~B()
96    {
97        printf(
98          "Hey I'm in derived class destructor number %d for %p.\n",
99          num_inst,
100          this
101        );
102              print();
103        num_inst--;
104    };
105
106    void print()  { printf("Derived class - %s\n", string); }
107};
108
109
110A foo;
111B foobar;
112
113void
114cdtest(void)
115{
116    A bar, blech, blah;
117    B bleak;
118
119    cout << "Testing a C++ I/O stream" << endl;
120
121    bar = blech;
122}
123
124//
125// main equivalent
126//      It can not be called 'main' since the bsp owns that name
127//      in many implementations in order to get global constructors
128//      run.
129//
130//      Ref: c/src/lib/libbsp/hppa1_1/pxfl/startup/bspstart.c
131//
132
133
134rtems_task main_task(
135  rtems_task_argument ignored
136)
137{
138    printf( "\n\n*** CONSTRUCTOR/DESTRUCTOR TEST ***\n" );
139
140    cdtest();
141
142    printf( "*** END OF CONSTRUCTOR/DESTRUCTOR TEST ***\n\n\n" );
143
144    exit(0);
145}
Note: See TracBrowser for help on using the repository browser.