File: test7.2.1.cc

package info (click to toggle)
libcwd 1.0.4-1.1
  • links: PTS
  • area: non-free
  • in suites: jessie, jessie-kfreebsd
  • size: 8,136 kB
  • ctags: 10,313
  • sloc: cpp: 23,354; sh: 9,798; ansic: 1,172; makefile: 852; exp: 234; awk: 11
file content (49 lines) | stat: -rw-r--r-- 1,036 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "sys.h"
#include "debug.h"

using namespace libcwd;

template<typename T1, typename T2>
  struct Foo {
    T1 for_me;
    T2 for_you;
    double d;
  };

int main(void)
{
  Debug( libcw_do.on() );
  Debug( dc::malloc.on() );
  Debug( dc::notice.on() );

  Foo<char, int>* f = new Foo<char, int>;
  AllocTag(f, "Our test object");

  int* p = &f->for_you;	// Pointer that points inside `f'

  Dout(dc::notice, "f == " << static_cast<void*>(f));
  Dout(dc::notice, "p == " << static_cast<void*>(p));

#ifdef CWDEBUG
  alloc_ct const* alloc = find_alloc(p);
  Dout(dc::notice,
	 "p points inside \""
      << alloc->description()
      << "\" starting at "
      << alloc->start()
      << " with size "
      << alloc->size()
      << '.');
  Dout(dc::notice,
	 "This memory block contains a \""
      << alloc->type_info().demangled_name() << "\".");
  Dout(dc::notice,
	 "The allocation type is `"
      << alloc->memblk_type()
      << "' and was allocated at "
      << alloc->location()
      << '.');
#endif

  return 0;
}