1

Consider this:

#include <iostream>
class Base {
public:
    Base()=default;   // though ctor,dctor are never called
    ~Base()=default;
};
int main()
{
    Base b();   //1 or Base b(void) produces same result
    return 0;   //2 Base b = Base(); please don't consider this
}

Now consider snippet from debugger:

Reading symbols from /home/a.out...done.
(gdb) run
Starting program: /home/a.out

Breakpoint 1, main () at main.cpp:12
12          return 0;

(gdb) ptype b
type = const union {
    int i[2];
    double d;
}
(gdb) print b
$1 = {i = {0, 1068498944}, d = 0.0625}

(gdb) ptype Base
type = class Base {
  public:
    Base(void);
    ~Base(int);
}

My point of Interest:

Yes, the above snippet is pretty basic but I fail to understand the data revealed by debugger(not the cmds itself).

  • Why this method fails to initialize class object?
  • Why 'ptype b' reveals a type union?
  • What does the values in 'b' symbolizes?

What have been done so far.

  • I have executed above snippet in MS visual 2015 - dbg fails to watch object 'b'. I never stepped into class Base b (as it should be, class Base is never instantiated).
  • Anyhow, GCC comes next - now we have above snippet to think about, gcov profiler shows no traces of code coverage for class Base, it validates our above MS visual's axiom.

code/execute- onlinegdb.com

Viktor Wolf
  • 133
  • 1
  • 10

0 Answers0