views:

26

answers:

3

I have the below code that links and runs fine in 32bit mode -

#include "safeint3.hpp"
typedef SafeInt<SIZE_T> SAFE_SIZE_T;
SAFE_SIZE_T sizeOfCache;
SAFE_SIZE_T _allocateAmt;

Where safeint3.hpp is current version that can be found on Codeplex SafeInt. For those who are unaware of it, safeint is a template class that makes working with different integer types and sizes "safe". To quote channel 9 video on software - "it writes the code that you should".

Which is my case. I have a class that is managing a large in-memory cache of objects (>6gb) and I am very concerned about making sure that I don't have overflow/underflow issues on my pointers/sizes/other integer variables. In this use, it solves many problems.

My problem is coming when moving from 32bit dev mode to 64bit production mode. When I build the app in this mode, I'm getting the following linker warnings -

1>cachecontrol.obj : warning LNK4006: "bool __cdecl IntrinsicMultiplyUint64(unsigned __int64 const &,unsigned __int64 const &,unsigned __int64 *)" (?IntrinsicMultiplyUint64@@YA_NAEB_K0PEA_K@Z) already defined in ImageInRamCache.obj; second definition ignored
1>cachecontrol.obj : warning LNK4006: "bool __cdecl IntrinsicMultiplyInt64(__int64 const &,__int64 const &,__int64 *)" (?IntrinsicMultiplyInt64@@YA_NAEB_J0PEA_J@Z) already defined in ImageInRamCache.obj; second definition ignored

While I understand I can ignore the error, I would like either (a) prevent the warning from occurring or (b) make it disappear so that my QA department doesn't flag it as a problem. And after spending some time researching it, I cannot find a way to do either.

A: 

Are these function declared and defined in the header file and not declared as inline by any chance?

It looks like they're quasi-inlined but the symbols are visible outside the object file, which they shouldn't be.

If that's the case, simply declaring them as inline should fix the issue.

Timo Geusch
A: 

Regarding your question about disabling the warning, this should do it:

#pragma warning(disable:4006)
bshields
A: 

The problem is that inside safeint3.hpp, the code looks like this:

bool IntrinsicMultiplyUint64( const unsigned __int64& a, const unsigned __int64& b, unsigned __int64* pRet )
{
    ....
}

This means every translation unit that includes safeint3.hpp will get a definition of IntrinsicMultiplyUint64. If you are willing to modify that file, you can make those functions inline:

inline bool IntrinsicMultiplyUint64( const unsigned __int64& a, const unsigned __int64& b, unsigned __int64* pRet )
{
    ....
}
R Samuel Klatchko
I added inline to both IntrinsicMultiplyUint64 (line 1643) and to IntrinsicMultiplyInt64 (line 1651) and that solved my problem. Thanks. In looking at the code, it is not obvious why because my "intellesense" is telling me that those lines are not compiled. So I'm still somewhat confused, but my program is working now, so thanks
photo_tom