MATLAB: Need to maintain two matlab codebases for generating both 32 and 64 bit C or C++ code

MATLAB Compiler

On the mathwork webpage for "Upgrading MEX-Files to Use 64-Bit API",under the heading "Update Arguments Used to Call Functions in the 64-Bit API," it shows that I might need to replace my current value with mw types (the example shows ints being replaced by mwSize).
If I wanted be able to compile to both 32 and 64 bit, would I have to maintain two matlab code versions (using the example, one with int values and the other with mwSize), or would the 64 bit data structures be "downcast" to the 32 bit types, so I would need to maintain only one codebase?

Best Answer

When compiling with a 64 bit version of Matlab, mwSize is a 64 bit integer used for addressing. And in a 32 bit version, mwSize is automatically defined as 32 bit integer. So using mwSize, mwIndex and mwSignedIndex is enough to support both platforms.
In addition you can use uint32_T etc. whenever you need an specific integer type. This reduces the dependencies to the underlying platform and the effort needed for testing and debugging. These specific integer types are defined in "tmwtypes.h", which is included from "mex.h" automatically.