TITLE: std::vector base address (Source: comp.lang.c++.moderated, 28 Nov 2000) GALLUCCI: "David Gallucci" >std::vector iVec; >int* pI = &iVec[0] > >is it guaranteed that pI will point to the base address? ( assuming of >course that no reallocation takes place ) SUTTER: "Herb Sutter" Yes. All existing implementations do this, and the guarantee was formally added last month as part of Technical Corrigendum #1 to the C++ Standard. I also discussed this issue in detail in my column "Standard Library News, Part 1: Vectors and Deques" (C++ Report, 11(7), July/August 1999). In particular, the reason you give is in fact the biggest motivation for having this guarantee: GALLUCCI: >Is this concept too dependent on vector's implementation? I need a managed >array, but I need to be able to pass the base address to a C function. I'd >rather reuse something that already exists, but I need to make sure that >this will work regardless of possible changes to vector's implementation. >Am I violating the black box? SUTTER: The first question addressed in that article is: "Can you use a vector interchangeably with a C-style array (say, with an existing function that expects an array)?" We want to encourage people writing new code to use vector instead of plain old arrays, because vectors are safer, automatically manager, and so forth. That would be much more difficult if a vector weren't usable with legacy code that expects C-style arrays, such as a (T* ptr, size_t len) argument list, so it's important that they be compatible. _______________________________________________ cpptips mailing list http://cpptips.hyperformix.com