Re: Bound Checking Cross Platform
On Tue, 21 Sep 2010 20:25:35 -0700 (PDT), Immortal Nephi
<Immortal_Nephi@hotmail.com> wrote:
at() function of vector has bound checking. It does include
_SCL_SECURE and _SCL_SECURE_VALIDATE macros. They are Microsoft
specification. What about other platforms such as Mac OS X and Linux?
These are implementation specific macros. They are not supported on
Mac OS or Linux. Your classes should ignore and never use those
macros, they are internal to the Microsoft implementation.
If your source code uses Microsoft Visual C++, it uses Win32 API to
call MessageBoxW(?) if assertion or exception is triggered. How can
source code have portability? If port to Mac OS X or Linux, which API
function can be used to trigger assertion or exception? It would be
either iostream or X Windows.
The response to an exception is implementation and OS defined. Whether
or not the system pops a dialog or not is specific to the system. The
system's response to an out of bounds condition can even change with
the type of build you are doing. For example:
# include <vector>
int main()
{
std::vector<int> v;
std::vector<int>::iterator i = v.begin();
v.push_back(1); // to bad invalidates all iterators including i
--i; // error - iterator no longer valid
}
This code pops a message box with the message "vector iterator not
decrementable" in Debug mode but the same project doesn't pop anything
in Release mode. The bounds checking is implemented in the debug
libraries but not in the release version.
This same code doesn't pop any dialogs in Xcode 2.5 debugger in debug
mode.