macro declaration

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 
2,147件の閲覧回数
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.

ラベル(1)
0 件の賞賛
返信
1 解決策
1,760件の閲覧回数
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 件の賞賛
返信
6 返答(返信)
1,760件の閲覧回数
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 件の賞賛
返信
1,760件の閲覧回数
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 件の賞賛
返信
1,761件の閲覧回数
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 件の賞賛
返信
1,760件の閲覧回数
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 件の賞賛
返信
1,760件の閲覧回数
ustcsnaker
Contributor I

Hi,

You are right. So, CrasyCat is also right.

Thank you.

0 件の賞賛
返信
1,760件の閲覧回数
ustcsnaker
Contributor I
Spoiler
 

Thank you very much, CrasyCat.

 

Hope to get your help if I have problems.

 

ustcsnaker

0 件の賞賛
返信