For in Macros??

M

Mayur K

I tried to include this macro in my code:
#define GET_BITS(NoOfBits,GetInThis) for(TInt i=0,GetInThis =
0x0;i<NoOfBits;i++,ByteData = ByteData << 1,GetInThis = GetInThis <<
1){ if((ByteData & 0x80) == 0x80){ GetInThis = GetInThis|0x01;} }

Sorry for the one big line.
This code gets compiled properly , but is not executing .
Can somebody point any errors in this macro.
Also is for and while i.e. bacsically iteration statements allowed in
macros.
Thanks.
--Mayur K.
 
C

CBFalconer

Mayur said:
I tried to include this macro in my code:
#define GET_BITS(NoOfBits,GetInThis) for(TInt i=0,GetInThis =
0x0;i<NoOfBits;i++,ByteData = ByteData << 1,GetInThis = GetInThis <<
1){ if((ByteData & 0x80) == 0x80){ GetInThis = GetInThis|0x01;} }

Sorry for the one big line.

So format it properly. We won't bother.
 
E

Eric Sosman

Mayur said:
I tried to include this macro in my code:
#define GET_BITS(NoOfBits,GetInThis) for(TInt i=0,GetInThis =
0x0;i<NoOfBits;i++,ByteData = ByteData << 1,GetInThis = GetInThis <<
1){ if((ByteData & 0x80) == 0x80){ GetInThis = GetInThis|0x01;} }

Sorry for the one big line.
This code gets compiled properly , but is not executing .

Please post a short, complete, compilable program
that demonstrates the problem. Without context, it's
all but impossible to debug an isolated snippet.
Can somebody point any errors in this macro.

I can see one probable error (and several shortcomings),
but without context I can't tell for sure.
Also is for and while i.e. bacsically iteration statements allowed in
macros.

Yes. Macros can expand to almost anything in the
C language. The only things a macro cannot produce are
preprocessor directives. (And comments, and inter-token
white space, and other such non-code "formatting" elements.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top