C++ Question
Is this valid in the C++ STL?
When I say legal, I don't mean will it compile, it does without warning. I mean, does STL guarantee that when I do &buffer.front() that the returned pointer points to the raw internal array. It does indeed work that way in MSVC++ 7.1, but is that portable?std::vector<unsigned char> buffer;
buffer.resize(100);
memcpy(&buffer.front(), "foo", strlen("foo"));

2 Comments:
The canonical way of getting the pointer to contiguous storage in a vector is &buffer[0]. That is indeed guaranteed to work portably.
&buffer.front() will give the same result as &buffer[0] in your example, so that's safe too. I'm not sure if front() is well-behaved if the vector can be empty, though. Probably not.
char[8] ch = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }
long some_long=0;
How can I concatenate ch into some_long?
So that some_long=12345678;
Post a Comment
<< Home