macro declaration

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

macro declaration

Jump to solution
995 Views
ustcsnaker
Contributor I

Hi,everyone!

 

When I compile my C coding, there was an error that C2801: ' ; '  missing. The codes are as follows.

 

#define     FAN_LOWSPEED_OFF()           PTDDD_PTDDD5 = 1;\  

                                                                          IO_vResetPin(PTED_PTED0)

 

I don't know much about the macro declaration. Is there anything wrong with my codes?

 

Any ideas about dealing with my errors?

 

Thanks much for your replies.

Labels (1)
0 Kudos
1 Solution
608 Views
CrasyCat
Specialist III

Hello

 

CodeWarrior supports nested macros.

But you need to make sure the macro IO_vResetPin is defined prior to FAN_LOWSPEED_OFF.

 

Additionally when you have parameter inside of macros it is  a good practice to enclose the parameter name in parenthesis 

For example:

    #define    IO_vResetPin(PinName)      (PinName) = 0 

 

As general note when you are using macros in an ANSI C module, if you get into trouble, check the preprocessor listing.

This listing will show you how the preprocessor expands the various macros and will allow you to detect any error using the macros. 

 

CrasyCat

View solution in original post

0 Kudos
6 Replies
608 Views
CrasyCat
Specialist III

Hello

 

I am missing some context information in order to answer properly.

 

But as far as I can tell IO_vResetPin is a function you are invoking,

I would first try to add a semicolon at the end of  IO_vResetPin(PTED_PTED0).

 

If that does not help generate the preprocessor listing for the source file and inspect the code at the location where the macro is expanded.

This might give you a clue.

 

CrasyCat

0 Kudos
608 Views
ustcsnaker
Contributor I

CrasyCat wrote:

Hello

 

I am missing some context information in order to answer properly.

 

But as far as I can tell IO_vResetPin is a function you are invoking,

I would first try to add a semicolon at the end of  IO_vResetPin(PTED_PTED0).

 

If that does not help generate the preprocessor listing for the source file and inspect the code at the location where the macro is expanded.

This might give you a clue.

 

CrasyCat



CrasyCat wrote:

Hello

 

I am missing some context information in order to answer properly.

 

But as far as I can tell IO_vResetPin is a function you are invoking,

I would first try to add a semicolon at the end of  IO_vResetPin(PTED_PTED0).

 

If that does not help generate the preprocessor listing for the source file and inspect the code at the location where the macro is expanded.

This might give you a clue.

 

CrasyCat




Thanks very much, CrasyCat.

 

I've worked it out. In fact, IO_vResetPin() is also a macro decfinition.The codes are as follows.

 

#define    IO_vResetPin(PinName)      PinName = 0 

 

I used PTED_PTED0 = 0 instead of  IO_vResetPin(PTED_PTED0). And as you said, I added a semicolon at the end of 

PTED_PTED0 = 0. It was ok.

 

I wonder if codewarrior doesn't support  macro definition nesting.

 

Thanks very much for your replies.

0 Kudos
609 Views
CrasyCat
Specialist III

Hello

 

CodeWarrior supports nested macros.

But you need to make sure the macro IO_vResetPin is defined prior to FAN_LOWSPEED_OFF.

 

Additionally when you have parameter inside of macros it is  a good practice to enclose the parameter name in parenthesis 

For example:

    #define    IO_vResetPin(PinName)      (PinName) = 0 

 

As general note when you are using macros in an ANSI C module, if you get into trouble, check the preprocessor listing.

This listing will show you how the preprocessor expands the various macros and will allow you to detect any error using the macros. 

 

CrasyCat

0 Kudos
608 Views
bigmac
Specialist III

Hello,

 

There was actually a further level of macro nesting used.  PTED_PTED0 is also a macro that defines an element of a bit field.

 

Regards,

Mac

 

0 Kudos
608 Views
ustcsnaker
Contributor I

Hi,

You are right. So, CrasyCat is also right.

Thank you.

0 Kudos
608 Views
ustcsnaker
Contributor I
Spoiler
 

Thank you very much, CrasyCat.

 

Hope to get your help if I have problems.

 

ustcsnaker

0 Kudos