From ce01d75d1c789c4fe0531111df716d3095f8f8e8 Mon Sep 17 00:00:00 2001 From: Davis King Date: Fri, 10 Jul 2009 22:31:47 +0000 Subject: [PATCH] Changed code to compile in visual studio 2003 --HG-- extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403113 --- dlib/algs.h | 5 ++++- .../member_function_pointer_kernel_1.h | 8 +++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/dlib/algs.h b/dlib/algs.h index 08613475a..b0a3f5361 100644 --- a/dlib/algs.h +++ b/dlib/algs.h @@ -764,7 +764,6 @@ namespace dlib and properly aligned to hold any kind of object. !*/ public: - static const unsigned long size = bSIZE; stack_based_memory_block(): data(mem.data) {} @@ -782,6 +781,10 @@ namespace dlib !*/ private: + + // You obviously can't have a block of memory that has zero bytes in it. + COMPILE_TIME_ASSERT(bSIZE > 0); + union mem_block { // All of this garbage is to make sure this union is properly aligned diff --git a/dlib/member_function_pointer/member_function_pointer_kernel_1.h b/dlib/member_function_pointer/member_function_pointer_kernel_1.h index 51021dc6b..6fa82d3a6 100644 --- a/dlib/member_function_pointer/member_function_pointer_kernel_1.h +++ b/dlib/member_function_pointer/member_function_pointer_kernel_1.h @@ -164,7 +164,13 @@ namespace dlib protected: - stack_based_memory_block mp_memory; + // The reason for adding 1 here is because visual studio 2003 will sometimes + // try to compile this code with sizeof(mp_null_impl) == 0 (which is a bug in visual studio). + // Fortunately, no actual real instances of this template seem to end up with that screwed up + // value so everything works fine if we just add 1 so that this degenerate case doesn't cause + // trouble. Note that we know it all works fine because safe_clone() checks the size of this + // memory block whenever the member function pointer is used. + stack_based_memory_block mp_memory; void destroy_mp_memory ( )