Back to index

cell-binutils  2.17cvs20070401
cdtest-foo.cc
Go to the documentation of this file.
00001 // Class Foo
00002 #pragma implementation
00003 
00004 
00005 // We don't use header files, since we only want to see, whether the
00006 // compiler is installed properly.
00007 //
00008 #if (__GNUG__ == 2)
00009 typedef __SIZE_TYPE__ size_t;
00010 #else
00011 typedef unsigned int size_t;
00012 #endif
00013 
00014 extern "C" {
00015     char *strncpy (char* dest, const char* dest, size_t len);
00016     int printf (const char*, ...);
00017 };
00018 
00019 #include "cdtest-foo.h"
00020 
00021 int Foo::foos = 0;
00022 
00023 void Foo::init_foo ()
00024 {
00025     printf ("BROKENLY calling Foo::init_foo from __init_start; size_of(Foo) = %ld\n", (long) sizeof(Foo));
00026     foos = FOOLISH_NUMBER;
00027 }
00028 
00029 
00030 Foo::Foo ()
00031 {
00032     i = ++foos;
00033     strncpy (message, "default-foo", len);
00034 #ifdef WITH_ADDR
00035     printf ("Constructing Foo(%d) \"default-foo\" at %08x\n", i, this);
00036 #else
00037     printf ("Constructing Foo(%d) \"default-foo\"\n", i);
00038 #endif
00039 }
00040 
00041 Foo::Foo (const char* msg)
00042 {
00043     i = ++foos;
00044     strncpy( message, msg, len);
00045 #ifdef WITH_ADDR
00046     printf ( "Constructing Foo(%d) \"%s\" at %08x\n", i, message, this);
00047 #else
00048     printf ( "Constructing Foo(%d) \"%s\"\n", i, message);
00049 #endif
00050 }
00051 
00052 
00053 Foo::Foo (const Foo& foo)
00054 {
00055     i = ++foos;
00056 #ifdef WITH_ADDR
00057     printf ("Initializing Foo(%d) \"%s\" at %08x with Foo(%d) %08x\n", 
00058            i, foo.message, this, foo.i, &foo);
00059 #else
00060    printf ("Initializing Foo(%d) \"%s\" with Foo(%d)\n",i, foo.message, foo.i);
00061 #endif
00062     for ( int k = 0; k < FOO_MSG_LEN; k++) message[k] = foo.message[k];
00063 }
00064 
00065 
00066 Foo& Foo::operator= (const Foo& foo)
00067 {
00068 #ifdef WITH_ADDR
00069     printf ("Copying Foo(%d) \"%s\" at %08x to Foo(%d) %08x\n", 
00070            foo.i, foo.message, &foo, i, this);
00071 #else
00072    printf ("Copying Foo(%d) \"%s\" to Foo(%d)\n", foo.i, foo.message, i);
00073 #endif
00074     for ( int k = 0; k < FOO_MSG_LEN; k++) message[k] = foo.message[k];
00075     return *this;
00076 }
00077 
00078 
00079 Foo::~Foo ()
00080 {
00081     foos--;
00082 #ifdef WITH_ADDR
00083     printf ("Destructing Foo(%d) \"%s\" at %08x (remaining foos: %d)\n",
00084            i, message, this, foos);
00085 #else
00086     printf ("Destructing Foo(%d) \"%s\" (remaining foos: %d)\n",
00087            i, message, foos);
00088 #endif
00089 }