59 lines · cpp
1// I made this example after noting that I was unable to display an unsized2// static class array. It turns out that gcc 4.2 will emit DWARF that correctly3// describes the PointType, but it will incorrectly emit debug info for the4// "g_points" array where the following things are wrong:5// - the DW_TAG_array_type won't have a subrange info6// - the DW_TAG_variable for "g_points" won't have a valid byte size, so even7// though we know the size of PointType, we can't infer the actual size8// of the array by dividing the size of the variable by the number of9// elements.10 11#include <stdio.h>12 13typedef struct PointType14{15 int x, y;16} PointType;17 18class A19{20public:21 static PointType g_points[];22};23 24// Make sure similar names don't confuse us:25 26class AA27{28public:29 static PointType g_points[];30};31 32PointType A::g_points[] = 33{34 { 1, 2 },35 { 11, 22 }36};37static PointType g_points[] = 38{39 { 3, 4 },40 { 33, 44 }41};42 43PointType AA::g_points[] = 44{45 { 5, 6 },46 { 55, 66 }47};48 49int50main (int argc, char const *argv[])51{52 const char *hello_world = "Hello, world!";53 printf ("A::g_points[1].x = %i\n", A::g_points[1].x); // Set break point at this line.54 printf ("AA::g_points[1].x = %i\n", AA::g_points[1].x);55 printf ("::g_points[1].x = %i\n", g_points[1].x);56 printf ("%s\n", hello_world);57 return 0;58}59