Category: Proxy usage


How do I deal with null references?


There is a big difference between a C++ NULL and a Java null: NULL is a preprocessor macro that's usually defined to something like

#define NULL   ((void*)0) 

and null (in lowercase) usually doesn't even exist in C++. The Codemesh runtime defines an xmog_null type whose definition is included by every proxy include file and thereby also included by your code which uses the proxy types. This include file instantiates a global instance of an xmog_null object by the name of "null", i.e.

static xmog_null      null; 

This allows you to use the identifier null in every compilation unit that uses C++ proxy types. The proxy types and the xmog_null type are designed to support a wide range of operations. You can for example initialize any proxy variable to null, you can compare any proxy object against null, and in general you can use null in any place that expects a proxy object.

It's actually a bit more complicated than described above. Some C++ frameworks use the identifier null already and we wanted to be able to coexist with these frameworks. Consequently, we allow you to redefine the name under which you refer to the Codemesh null instance via a preprocessor definition. You can optionally use the XMOG_NULL_NAME macro to provide your desired name. You will then of course have to change any code that uses null to use the defined name instead.

One last caution: don't make the mistake of confusing NULL and null! Hopefully, this will cause a compilation error in all places where you try to use NULL instead of null, but be vigilant and try to use null.

Copyright 2006-2011 by Codemesh, Inc., ALL RIGHTS RESERVED

frequently asked questions
home products support customers partners newsroom about us contact us