03-15-2006 10:36 AM
03-15-2006 11:07 AM
The problem you are seeing is that the CVI user protection is detecting a NULL dereference (which is correct, as far as is goes). This should only happen in debug mode, release mode should work just fine.
To work around this, you could modify your macro to disable protection errors around this code, similar to the following:
#if _CVI_DEBUG_
#define IMPL_HELPER(class, member, pointer) \
(&((class *)0)->member == pointer, ((class *) (((long) pointer) - offsetof(class, member))))
#define GET_IMPL(class, member, pointer, impl) \
do { \
int state = SetBreakOnProtectionErrors(0); \
impl = IMPL_HELPER(class, member, pointer); \
SetBreakOnProtectionErrors(state); \
} while (0)
#else
#define GET_IMPL(class, member, pointer, impl) \
(impl = (&((class *)0)->member == pointer, ((class *) (((long) pointer) - offsetof(class, member)))))
#endif
This doesn't allow the more straightforward usage, but works. You could probably work some more macro magic and get the nice usage back, depending on how much code you have that depends on it.
To see how we "work around" this in our libraries, you can compare CVI's definition of offsetof() to the one in included in your code; it is defined in cvixx\include\ansi\stddef.h:
#define offsetof(t, mem) ((size_t) ((char *)&(((t *)8)->mem) - (char *)8))
Hope this helps,
-alex
03-15-2006 11:08 AM - edited 03-15-2006 11:08 AM
Message Edited by DaveC on 03-15-2006 11:09 AM
03-15-2006 11:47 AM