How to clear this offset bit?

Started by
3 comments, last by swiftcoder 8 years, 1 month ago

void Remove(const T* inValue)
{
    int offset = inValue->x*MAXTILE_YLEN + inValue->z;
    mbVisited[offset] &= ~(1 << inValue->direction);
    Count--;
}

BYTE     mbVisited[MAXTILE_XLEN*MAXTILE_YLEN];

I want to clear the corresponding mbVisited bit based on the x,y and dir given as
the argument to Remove.
But I am not sure if this would work or not?
Thanks
Jack

Advertisement
Did you test it? We are not your Visual Studio debugger.

You did not give us enough information and it would have been faster just to try it in your debugger (since you have already written the code).
The array is based off X and Y but your offset is calculated via X and Z. Why?
Is direction the bit index into that byte? 0-7?

You’ve already written it, so why did you post it here instead of just testing it in a debugger? Why don’t you tell us if it works or not?


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

I need to check it. But for the time being, it is working as normal.

But I am not sure, because I copy it off somewhere from the web.

You could verify the function by reading the documentation of the bitwise operators used therein, and testing it by feeding various values to it and comparing the returned values with known, expected values. It would also be a good chance to learn unit testing.

It is dangerous to use copy/pasted code in production projects, if you don't understand what it does. When stuff breaks, it is your fault, whether or not you understand why.

Niko Suni

Unit tests are your friend. An important step when integrating 3rd-party code is to write unit/integration tests that ensure it does in fact work as you think it does.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

This topic is closed to new replies.

Advertisement