473,387 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

_HAS_ITERATOR_DEBUGGING and std::vector

Hi,

I sometimes convert std::vector::iterators to pointers by the (afaik)
legal construct &v[0], e.g. in the construct below. In debug build, the
program terminates, because of what seems to be part of the new checked
iterators in VC8. OTOH, I thought that the code is perfectly legal. Is
it safe to temporarily disable _HAS_ITERATOR_DEBUGGING here? I feel
bad about just shutting up the compiler.

Thanks!

bool QuadsFileIO::Read(const std::string& fn, std::vector<float>&
verts, std::vector<float>& texcoords) {
ifstream ifile(fn.c_str(), ios::binary | ios::in);
if (!ifile.is_open())
{
std::cout << "Warning: Couldn't open file for reading " << fn <<
std::endl;
return false;
}

typedef std::vector<float>::size_type size_type;
size_type size;
ifile.read((char*)&size, sizeof(size_type));

verts.resize(size);
texcoords.resize(size);

ifile.read((char*)&verts[0], sizeof(float) * size);
ifile.read((char*)&texcoords[0], sizeof(float) * size);

ifile.close();

return true;
}

May 14 '06 #1
1 2816
> I sometimes convert std::vector::iterators to pointers by the (afaik)
legal construct &v[0], e.g. in the construct below. In debug build, the
program terminates, because of what seems to be part of the new checked
iterators in VC8. OTOH, I thought that the code is perfectly legal. Is
it safe to temporarily disable _HAS_ITERATOR_DEBUGGING here? I feel
bad about just shutting up the compiler.

&v[0] is perfectly valid so long as v has at least one element.
You should check that size != 0.

Otherwise, I fail to see why iterator debugging would cause
problems here. Can you get us the exact diagnostic and the call
stack?

-hg
May 14 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
by: Jason Heyes | last post by:
To my understanding, std::vector does not use reference counting to avoid the overhead of copying and initialisation. Where can I get a reference counted implementation of std::vector? Thanks.
18
by: Janina Kramer | last post by:
hi ng, i'm working on a multiplayer game for a variable number of players and on the client side, i'm using a std::vector<CPlayer> to store informatik about the players. CPlayer is a class that...
20
by: Anonymous | last post by:
Is there a non-brute force method of doing this? transform() looked likely but had no predefined function object. std::vector<double> src; std::vector<int> dest; ...
17
by: Michael Hopkins | last post by:
Hi all I want to create a std::vector that goes from 1 to n instead of 0 to n-1. The only change this will have is in loops and when the vector returns positions of elements etc. I am calling...
8
by: Ross A. Finlayson | last post by:
I'm trying to write some C code, but I want to use C++'s std::vector. Indeed, if the code is compiled as C++, I want the container to actually be std::vector, in this case of a collection of value...
32
by: zl2k | last post by:
hi, c++ user Suppose I constructed a large array and put it in the std::vector in a function and now I want to return it back to where the function is called. I can do like this: ...
56
by: Peter Olcott | last post by:
I am trying to refer to the same std::vector in a class by two different names, I tried a union, and I tried a reference, I can't seem to get the syntax right. Can anyone please help? Thanks
9
by: aaragon | last post by:
I am trying to create a vector of type T and everything goes fine until I try to iterate over it. For some reason, the compiler gives me an error when I declare std::vector<T>::iterator iter;...
13
by: jubelbrus | last post by:
Hi I'm trying to do the following. #include <vector> #include <boost/thread/mutex.hpp> #include <boost/shared_ptr.hpp> #include <boost/tuple/tuple.hpp> class {
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.