#include <iostream.h>
#define MODE1 = 1;
#define MODE2 = 2;
#define MODE3 = 4;
#define MODE4 = 8;
int main()
{
unsigned char Mode = 5;
if (Mode & MODE1 == MODE1)
{cout << "Mode 1 ";}
if (Mode & MODE2 == MODE2)
{cout << "Mode 2 ";}
if (Mode & MODE3 == MODE3)
{cout << "Mode 3 ";}
if (Mode & MODE4 == MODE4)
{cout << "Mode 4 ";}
return 0;
}
What's wrong?
Thanx,
Marty
[edited by - Marty666 on March 19, 2003 1:27:55 PM]
Very, very simple/stupid question...
Hi all..
I've written this very simple example of what goes wrong in my prog. that I don't seem to get.
_____ /____ /|| | || MtY | ||_____|/Marty
you may want to remove those equal signs ''='' from the defines ... that''s the only error i can find....
--------<a href="http://www.icarusindie.com/rpc>Reverse Pop Culture
What I want to happen is: If I put 1 in ''Mode'' it only writes "Mode1" to the screen...
If I put in 2, "Mode2 "
... 3 "Mode1 Mode2 "
... 4 "Mode3 "
... 5 "Mode1 Mode3 "
It''s like 8 flags in the unsigned char. I''ve got a 4 flags in this example (MODE1 to MODE4) which i defined. With a logical AND I want to check if this mode is activated. (If the correct bit is set to 1). To check this, I have the example write "Mode# " to the screen... I use 5 in the example so it should say "Mode1 Mode3 "
Thanx, Marty
PS: This is what c++ tells me:
Compiling...
andtest.cpp
error C2059: syntax error : ''=''
error C2143: syntax error : missing '';'' before ''==''
error C2143: syntax error : missing '';'' before '')''
error C2143: syntax error : missing '';'' before ''{''
error C2059: syntax error : ''=''
error C2143: syntax error : missing '';'' before ''==''
error C2143: syntax error : missing '';'' before '')''
error C2143: syntax error : missing '';'' before ''{''
error C2059: syntax error : ''=''
error C2143: syntax error : missing '';'' before ''==''
error C2143: syntax error : missing '';'' before '')''
error C2143: syntax error : missing '';'' before ''{''
error C2059: syntax error : ''=''
error C2143: syntax error : missing '';'' before ''==''
error C2143: syntax error : missing '';'' before '')''
error C2143: syntax error : missing '';'' before ''{''
Error executing cl.exe.
andtest.exe - 16 error(s), 0 warning(s)
If I put in 2, "Mode2 "
... 3 "Mode1 Mode2 "
... 4 "Mode3 "
... 5 "Mode1 Mode3 "
It''s like 8 flags in the unsigned char. I''ve got a 4 flags in this example (MODE1 to MODE4) which i defined. With a logical AND I want to check if this mode is activated. (If the correct bit is set to 1). To check this, I have the example write "Mode# " to the screen... I use 5 in the example so it should say "Mode1 Mode3 "
Thanx, Marty
PS: This is what c++ tells me:
Compiling...
andtest.cpp
error C2059: syntax error : ''=''
error C2143: syntax error : missing '';'' before ''==''
error C2143: syntax error : missing '';'' before '')''
error C2143: syntax error : missing '';'' before ''{''
error C2059: syntax error : ''=''
error C2143: syntax error : missing '';'' before ''==''
error C2143: syntax error : missing '';'' before '')''
error C2143: syntax error : missing '';'' before ''{''
error C2059: syntax error : ''=''
error C2143: syntax error : missing '';'' before ''==''
error C2143: syntax error : missing '';'' before '')''
error C2143: syntax error : missing '';'' before ''{''
error C2059: syntax error : ''=''
error C2143: syntax error : missing '';'' before ''==''
error C2143: syntax error : missing '';'' before '')''
error C2143: syntax error : missing '';'' before ''{''
Error executing cl.exe.
andtest.exe - 16 error(s), 0 warning(s)
_____ /____ /|| | || MtY | ||_____|/Marty
yep,..... it's those equal and ';' characters in your defines
do this:-
#define MODE1 1
#define MODE2 2
#define MODE3 4
#define MODE4 8
[edited by - Crawl on March 19, 2003 1:40:15 PM]
do this:-
#define MODE1 1
#define MODE2 2
#define MODE3 4
#define MODE4 8
[edited by - Crawl on March 19, 2003 1:40:15 PM]
--------<a href="http://www.icarusindie.com/rpc>Reverse Pop Culture
Ok, I removed the = signs... Now it gives 12 errors:
Compiling...
andtest.cpp
error C2143: syntax error : missing '')'' before '';''
warning C4390: '';'' : empty controlled statement found; is this the intent?
error C2143: syntax error : missing '';'' before ''==''
error C2059: syntax error : '')''
error C2143: syntax error : missing '')'' before '';''
warning C4390: '';'' : empty controlled statement found; is this the intent?
error C2143: syntax error : missing '';'' before ''==''
error C2059: syntax error : '')''
error C2143: syntax error : missing '')'' before '';''
warning C4390: '';'' : empty controlled statement found; is this the intent?
error C2143: syntax error : missing '';'' before ''==''
error C2059: syntax error : '')''
error C2143: syntax error : missing '')'' before '';''
warning C4390: '';'' : empty controlled statement found; is this the intent?
error C2143: syntax error : missing '';'' before ''==''
error C2059: syntax error : '')''
Error executing cl.exe.
andtest.exe - 12 error(s), 4 warning(s)
Compiling...
andtest.cpp
error C2143: syntax error : missing '')'' before '';''
warning C4390: '';'' : empty controlled statement found; is this the intent?
error C2143: syntax error : missing '';'' before ''==''
error C2059: syntax error : '')''
error C2143: syntax error : missing '')'' before '';''
warning C4390: '';'' : empty controlled statement found; is this the intent?
error C2143: syntax error : missing '';'' before ''==''
error C2059: syntax error : '')''
error C2143: syntax error : missing '')'' before '';''
warning C4390: '';'' : empty controlled statement found; is this the intent?
error C2143: syntax error : missing '';'' before ''==''
error C2059: syntax error : '')''
error C2143: syntax error : missing '')'' before '';''
warning C4390: '';'' : empty controlled statement found; is this the intent?
error C2143: syntax error : missing '';'' before ''==''
error C2059: syntax error : '')''
Error executing cl.exe.
andtest.exe - 12 error(s), 4 warning(s)
_____ /____ /|| | || MtY | ||_____|/Marty
k, now remove the '';'' from your #define statements:
this is BAD #define FOO 4;
this is GOOD #define FOO 4
#define is a pre-compiler directive. it''s not a normal line of c-code. you DON''T end it with a semi-colon
-me
this is BAD #define FOO 4;
this is GOOD #define FOO 4
#define is a pre-compiler directive. it''s not a normal line of c-code. you DON''T end it with a semi-colon
-me
unsigned char Mode = 5;
that does not equal 'Mode'
Please visit Turt99 Productions
EDIT: What I'm trying to get at is why is your varible mode a char? and then are you wanting to add the 2 variables?
[edited by - Turt99 on March 19, 2003 1:49:37 PM]
that does not equal 'Mode'
Please visit Turt99 Productions
EDIT: What I'm trying to get at is why is your varible mode a char? and then are you wanting to add the 2 variables?
[edited by - Turt99 on March 19, 2003 1:49:37 PM]
Thanx! It looks like this now...
One problem left: My output is:
"Mode1 Mode2 Mode3 Mode4 " whatever i put in Mode...
Marty
#include <iostream.h>#define MODE1 1#define MODE2 2#define MODE3 4#define MODE4 8int main(){ unsigned char Mode = 1; if (Mode & MODE1 == MODE1) {cout << "Mode 1 ";} if (Mode & MODE2 == MODE2) {cout << "Mode 2 ";} if (Mode & MODE3 == MODE3) {cout << "Mode 3 ";} if (Mode & MODE4 == MODE4) {cout << "Mode 4 ";} return 0;}
One problem left: My output is:
"Mode1 Mode2 Mode3 Mode4 " whatever i put in Mode...
Marty
_____ /____ /|| | || MtY | ||_____|/Marty
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement