Home | History | Annotate | Download | only in inlined_breakpoints
      1 // This file must have the following defined before it is included:
      2 // T defined to the type to test (int, float, etc)
      3 // T_CSTR a C string representation of the type T ("int", "float")
      4 // T_VALUE_1 defined to a valid initializer value for TEST_TYPE (7 for int, 2.0 for float)
      5 // T_VALUE_2, T_VALUE_3, T_VALUE_4 defined to a valid initializer value for TEST_TYPE that is different from TEST_VALUE_1
      6 // T_PRINTF_FORMAT defined if T can be printed with printf
      7 //
      8 // An example for integers is below
      9 #if 0
     10 
     11 #define T int
     12 #define T_CSTR "int"
     13 #define T_VALUE_1 11001110
     14 #define T_VALUE_2 22002220
     15 #define T_VALUE_3 33003330
     16 #define T_VALUE_4 44044440
     17 #define T_PRINTF_FORMAT "%i"
     18 
     19 #include "basic_type.cpp"
     20 
     21 #endif
     22 
     23 class a_class
     24 {
     25 public:
     26     a_class (const T& a, const T& b) :
     27         m_a (a),
     28         m_b (b)
     29     {
     30     }
     31 
     32     ~a_class ()
     33     {
     34     }
     35 
     36     const T&
     37     get_a()
     38     {
     39         return m_a;
     40     }
     41 
     42     void
     43     set_a (const T& a)
     44     {
     45         m_a = a;
     46     }
     47 
     48     const T&
     49     get_b()
     50     {
     51         return m_b;
     52     }
     53 
     54     void
     55     set_b (const T& b)
     56     {
     57         m_b = b;
     58     }
     59 
     60 protected:
     61     T m_a;
     62     T m_b;
     63 };
     64 
     65 typedef struct a_struct_tag {
     66     T a;
     67     T b;
     68 } a_struct_t;
     69 
     70 
     71 typedef union a_union_zero_tag {
     72     T a;
     73     double a_double;
     74 } a_union_zero_t;
     75 
     76 typedef struct a_union_nonzero_tag {
     77   double a_double;
     78   a_union_zero_t u;
     79 } a_union_nonzero_t;
     80 
     81 
     82 #include <stdint.h>
     83 #include <stdio.h>
     84 
     85 void Puts(char const *msg)
     86 {
     87     puts(msg);
     88 }
     89 
     90 int
     91 main (int argc, char const *argv[])
     92 {
     93     T a = T_VALUE_1;
     94     T* a_ptr = &a;
     95     T& a_ref = a;
     96     T a_array_bounded[2] = { T_VALUE_1, T_VALUE_2 };
     97     T a_array_unbounded[] = { T_VALUE_1, T_VALUE_2 };
     98 
     99     a_class a_class_instance (T_VALUE_1, T_VALUE_2);
    100     a_class *a_class_ptr = &a_class_instance;
    101     a_class &a_class_ref = a_class_instance;
    102 
    103     a_struct_t a_struct = { T_VALUE_1, T_VALUE_2 };
    104     a_struct_t *a_struct_ptr = &a_struct;
    105     a_struct_t &a_struct_ref = a_struct;
    106 
    107     // Create a union with type T at offset zero
    108     a_union_zero_t a_union_zero;
    109     a_union_zero.a = T_VALUE_1;
    110     a_union_zero_t *a_union_zero_ptr = &a_union_zero;
    111     a_union_zero_t &a_union_zero_ref = a_union_zero;
    112 
    113     // Create a union with type T at a non-zero offset
    114     a_union_nonzero_t a_union_nonzero;
    115     a_union_nonzero.u.a = T_VALUE_1;
    116     a_union_nonzero_t *a_union_nonzero_ptr = &a_union_nonzero;
    117     a_union_nonzero_t &a_union_nonzero_ref = a_union_nonzero;
    118 
    119     a_struct_t a_struct_array_bounded[2]  = {{ T_VALUE_1, T_VALUE_2 }, { T_VALUE_3, T_VALUE_4 }};
    120     a_struct_t a_struct_array_unbounded[] = {{ T_VALUE_1, T_VALUE_2 }, { T_VALUE_3, T_VALUE_4 }};
    121     a_union_zero_t a_union_zero_array_bounded[2];
    122     a_union_zero_array_bounded[0].a = T_VALUE_1;
    123     a_union_zero_array_bounded[1].a = T_VALUE_2;
    124     a_union_zero_t a_union_zero_array_unbounded[] = {{ T_VALUE_1 }, { T_VALUE_2 }};
    125 
    126 #ifdef T_PRINTF_FORMAT
    127     printf ("%s: a = '" T_PRINTF_FORMAT "'\n", T_CSTR, a);
    128     printf ("%s*: %p => *a_ptr = '" T_PRINTF_FORMAT "'\n", T_CSTR, a_ptr, *a_ptr);
    129     printf ("%s&: @%p => a_ref = '" T_PRINTF_FORMAT "'\n", T_CSTR, &a_ref, a_ref);
    130 
    131     printf ("%s[2]: a_array_bounded[0] = '" T_PRINTF_FORMAT "'\n", T_CSTR, a_array_bounded[0]);
    132     printf ("%s[2]: a_array_bounded[1] = '" T_PRINTF_FORMAT "'\n", T_CSTR, a_array_bounded[1]);
    133 
    134     printf ("%s[]: a_array_unbounded[0] = '" T_PRINTF_FORMAT "'\n", T_CSTR, a_array_unbounded[0]);
    135     printf ("%s[]: a_array_unbounded[1] = '" T_PRINTF_FORMAT "'\n", T_CSTR, a_array_unbounded[1]);
    136 
    137     printf ("(a_class) a_class_instance.m_a = '" T_PRINTF_FORMAT "'\n", a_class_instance.get_a());
    138     printf ("(a_class) a_class_instance.m_b = '" T_PRINTF_FORMAT "'\n", a_class_instance.get_b());
    139     printf ("(a_class*) a_class_ptr = %p, a_class_ptr->m_a = '" T_PRINTF_FORMAT "'\n", a_class_ptr, a_class_ptr->get_a());
    140     printf ("(a_class*) a_class_ptr = %p, a_class_ptr->m_b = '" T_PRINTF_FORMAT "'\n", a_class_ptr, a_class_ptr->get_b());
    141     printf ("(a_class&) a_class_ref = %p, a_class_ref.m_a = '" T_PRINTF_FORMAT "'\n", &a_class_ref, a_class_ref.get_a());
    142     printf ("(a_class&) a_class_ref = %p, a_class_ref.m_b = '" T_PRINTF_FORMAT "'\n", &a_class_ref, a_class_ref.get_b());
    143 
    144     printf ("(a_struct_t) a_struct.a = '" T_PRINTF_FORMAT "'\n", a_struct.a);
    145     printf ("(a_struct_t) a_struct.b = '" T_PRINTF_FORMAT "'\n", a_struct.b);
    146     printf ("(a_struct_t*) a_struct_ptr = %p, a_struct_ptr->a = '" T_PRINTF_FORMAT "'\n", a_struct_ptr, a_struct_ptr->a);
    147     printf ("(a_struct_t*) a_struct_ptr = %p, a_struct_ptr->b = '" T_PRINTF_FORMAT "'\n", a_struct_ptr, a_struct_ptr->b);
    148     printf ("(a_struct_t&) a_struct_ref = %p, a_struct_ref.a = '" T_PRINTF_FORMAT "'\n", &a_struct_ref, a_struct_ref.a);
    149     printf ("(a_struct_t&) a_struct_ref = %p, a_struct_ref.b = '" T_PRINTF_FORMAT "'\n", &a_struct_ref, a_struct_ref.b);
    150 
    151     printf ("(a_union_zero_t) a_union_zero.a = '" T_PRINTF_FORMAT "'\n", a_union_zero.a);
    152     printf ("(a_union_zero_t*) a_union_zero_ptr = %p, a_union_zero_ptr->a = '" T_PRINTF_FORMAT "'\n", a_union_zero_ptr, a_union_zero_ptr->a);
    153     printf ("(a_union_zero_t&) a_union_zero_ref = %p, a_union_zero_ref.a = '" T_PRINTF_FORMAT "'\n", &a_union_zero_ref, a_union_zero_ref.a);
    154 
    155     printf ("(a_union_nonzero_t) a_union_nonzero.u.a = '" T_PRINTF_FORMAT "'\n", a_union_nonzero.u.a);
    156     printf ("(a_union_nonzero_t*) a_union_nonzero_ptr = %p, a_union_nonzero_ptr->u.a = '" T_PRINTF_FORMAT "'\n", a_union_nonzero_ptr, a_union_nonzero_ptr->u.a);
    157     printf ("(a_union_nonzero_t&) a_union_nonzero_ref = %p, a_union_nonzero_ref.u.a = '" T_PRINTF_FORMAT "'\n", &a_union_nonzero_ref, a_union_nonzero_ref.u.a);
    158 
    159     printf ("(a_struct_t[2]) a_struct_array_bounded[0].a = '" T_PRINTF_FORMAT "'\n", a_struct_array_bounded[0].a);
    160     printf ("(a_struct_t[2]) a_struct_array_bounded[0].b = '" T_PRINTF_FORMAT "'\n", a_struct_array_bounded[0].b);
    161     printf ("(a_struct_t[2]) a_struct_array_bounded[1].a = '" T_PRINTF_FORMAT "'\n", a_struct_array_bounded[1].a);
    162     printf ("(a_struct_t[2]) a_struct_array_bounded[1].b = '" T_PRINTF_FORMAT "'\n", a_struct_array_bounded[1].b);
    163 
    164     printf ("(a_struct_t[]) a_struct_array_unbounded[0].a = '" T_PRINTF_FORMAT "'\n", a_struct_array_unbounded[0].a);
    165     printf ("(a_struct_t[]) a_struct_array_unbounded[0].b = '" T_PRINTF_FORMAT "'\n", a_struct_array_unbounded[0].b);
    166     printf ("(a_struct_t[]) a_struct_array_unbounded[1].a = '" T_PRINTF_FORMAT "'\n", a_struct_array_unbounded[1].a);
    167     printf ("(a_struct_t[]) a_struct_array_unbounded[1].b = '" T_PRINTF_FORMAT "'\n", a_struct_array_unbounded[1].b);
    168 
    169     printf ("(a_union_zero_t[2]) a_union_zero_array_bounded[0].a = '" T_PRINTF_FORMAT "'\n", a_union_zero_array_bounded[0].a);
    170     printf ("(a_union_zero_t[2]) a_union_zero_array_bounded[1].a = '" T_PRINTF_FORMAT "'\n", a_union_zero_array_bounded[1].a);
    171 
    172     printf ("(a_union_zero_t[]) a_union_zero_array_unbounded[0].a = '" T_PRINTF_FORMAT "'\n", a_union_zero_array_unbounded[0].a);
    173     printf ("(a_union_zero_t[]) a_union_zero_array_unbounded[1].a = '" T_PRINTF_FORMAT "'\n", a_union_zero_array_unbounded[1].a);
    174 
    175 #endif
    176     Puts("About to exit, break here to check values..."); // Set break point at this line.
    177     return 0;
    178 }
    179