Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "&varname == varname" mean?

Tags:

c++

I've inherited a C++ project at work, it's an application originally written for Windows XP that presents visual stimuli during psych experiments. I can't figure out this line here that checks for syntax errors in the control file:

else if((m_SectorSwitchData.SectorType &ET_TMS == ET_TMS) & (m_SectorSwitchData.SectorType | ET_TMS != ET_TMS))

I can't find any documentation on what the "&ET_TMS == ET_TMS" means, is it a typo? The Wikipedia page on C++ operators doesn't mention it and Visual Studio doesn't mark it wrong.

like image 808
bitmaker Avatar asked Nov 09 '18 16:11

bitmaker


People also ask

What does the fox say Meaning?

Speaking of the meaning of the song, Vegard characterizes it as coming from "a genuine wonder of what the fox says, because we didn't know". Although interpreted by some commentators as a reference to the furry fandom, the brothers have stated they did not know about its existence when producing "The Fox".

What does a real fox say?

The most commonly heard red fox vocalizations are a quick series of barks, and a scream-y variation on a howl. All fox vocalizations are higher-pitched than dog vocalizations, partly because foxes are much smaller. The barks are a sort of ow-wow-wow-wow, but very high-pitched, almost yippy.

How can I identify a song by sound?

On your phone, touch and hold the Home button or say "Hey Google." Ask "What's this song?" Play a song or hum, whistle, or sing the melody of a song. Hum, whistle, or sing: Google Assistant will identify potential matches for the song.


1 Answers

This is the bitwise and operation. To make it easier to parse you could add a space and some parentheses to make it easier to read:

(m_SectorSwitchData.SectorType & ET_TMS) == ET_TMS

Do note that this change will actually change the behavior of the code. & has a lower precedence than == so

(m_SectorSwitchData.SectorType & ET_TMS == ET_TMS)

is actually

(m_SectorSwitchData.SectorType & (ET_TMS == ET_TMS))

This is mostly a mistake by the original author and

((m_SectorSwitchData.SectorType & ET_TMS) == ET_TMS)

is most likely what they intended to have. This also applies to the second part of the if statement.

like image 93
NathanOliver Avatar answered Sep 28 '22 06:09

NathanOliver