5126
Developer's Corner / Re: Copy/pasting code and the last line effect
« Last post by mouser on December 11, 2015, 06:41 PM »actually there is a bigger bug here, though it's hard to be sure exactly what the author intended.
First things first, this looks like c++ code.
my guess is that the most likely bug is the declaration WORD m_wVertexIDs[3] should probably be WORD m_wVertexIDs[4];
creating a 4 element array(vector), indexed from 0 to 3, making the lines in the function correct. if so this is NOT an example of a last line effect, but a deadly c++ style error of declaring an array too small (which may not be flagged as an error).
It's certainly true that the Multi Theft Auto code example is incorrectly diagnosed -- that last line is not "redundant", it is an error (given the earlier declaration) -- one that would be caught in some languages or cause unpredictable memory problems in others.
First things first, this looks like c++ code.
my guess is that the most likely bug is the declaration WORD m_wVertexIDs[3] should probably be WORD m_wVertexIDs[4];
creating a 4 element array(vector), indexed from 0 to 3, making the lines in the function correct. if so this is NOT an example of a last line effect, but a deadly c++ style error of declaring an array too small (which may not be flagged as an error).
It's certainly true that the Multi Theft Auto code example is incorrectly diagnosed -- that last line is not "redundant", it is an error (given the earlier declaration) -- one that would be caught in some languages or cause unpredictable memory problems in others.

Recent Posts
