[vtk-developers] Visual Studio 8 heads up regarding &*x.end()

Andrew Maclean andrew.amaclean at gmail.com
Thu Mar 2 18:52:01 EST 2006


Hi all,

I am asking that if you are rewriting or adding new code, please be aware of
this issue as discussed below.

I have encountered a problem with Visual Studio 8 in relation to the issue
of dereferencing an iterator.

Code like (vtkClientServerStream.cxx line 240)

memcpy(&*this->Internal->Data.end() - length, data, length); will break in
debug mode using this compiler. You can get around it by doing something
like:

memcpy(&*(--this->Internal->Data.end()) - length + 1, data, length);
provided Data is not empty.

However I am uneasy with this approach.

In the same file at line 1205:

unsigned char* end = &*this->Internal->Data.end(); Will also always break
with the VC 8 compiler.

I have already filed a bug report for ParaView (2926) but I see that a
similar issue has also cropped up with ITK.

We are not alone in this, one person here at work has also been caught by
this one - they were dereferencing the end() marker to use it in a loop. I
myself was caught by a similar problem dereferencing the iterator but not
checking before I did it that it had reached end().

My personal view is that I don't like things like that exemplified by "
char* end = &*this->Internal->Data.end();" because there is an implicit
assumption here that the notion of half-open intervals in the STL is being
circumvented by this approach.

I apologize if this sounds autocratic, but I am trying to save us all lot of
grief in the future! I suspect other compilers will follow suit.

If anyone wants to contribute to a discussion as to what the best approach
should be please do.

Also please be aware that there is a bug in the compiler regarding
<sstream>; Namely stringstream or istringstream fail to read comma separated
lists of integers.

See:
http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=275546dc-710d-4503-bbf6-21d1dad15e36

And: http://www.codecomments.com/archive371-2006-1-778318.html for more
discussion. I don't recommend patching the STL! It is a deeper issue than
just the locale problem.

Note that setting the codepage only works for the first integer being read.

My fix works better but it means that the input stream has to be modified.

Andrew


--

___________________________________________
Andrew J. P. Maclean
Centre for Autonomous Systems
The Rose Street Building J04
The University of Sydney  2006  NSW
AUSTRALIA
Ph: +61 2 9351 3283
Fax: +61 2 9351 7474
URL: http://www.cas.edu.au/
___________________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20060303/d6db8d54/attachment.html>


More information about the vtk-developers mailing list