Set Boolean Variable to opposite, eg if true, set to false, and vice versa.

Started by
12 comments, last by Aardvajk 17 years, 10 months ago
Yeah here's the cool way.

flag ^= true;
Advertisement
m_bSelected = 1 - m_bSelected;
Quote:Original post by Anonymous Poster
m_bSelected = 1 - m_bSelected;


Hmm, I wouldn't have thought of that. Creative.

Anyway, OT: The whole BOOL = !BOOL is the way to go, as so many people said.
convert.cpp
void __export convert_bool(bool *b){    switch(*b)        {        case true : *b=false; break;        case false: *b=true; break;        default: throw error();        }}int WINAPI DllEntryPoint(HINSTANCE,DWORD,LPVOID){    return 1;}


Compile with BCC32 -WD convert.cpp.
Place resulting file in Windows->System32 folder.

main.cpp
#include <windows.h>int main(int,const char **av){    HMODULE Hm=LoadLibrary("convert.dll");    if(Hm==NULL) throw error();    void(*f)(bool*)=(void(*)(bool*))GetProcAddress("_convert_bool");    if(f==NULL) throw error();    bool b=true;    f(&b);    FreeLibray(Hm);    return 0;}


[Edited by - EasilyConfused on June 26, 2006 6:03:36 AM]

This topic is closed to new replies.

Advertisement