preprocessor directives in macros

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

preprocessor directives in macros

ソリューションへジャンプ
2,172件の閲覧回数
irob
Contributor V

Hey, everyone. I'm reaching my limit of C language understanding with this question. I've got some sample code written by Freescale, as part of one of their demo boards, the DEMO9S08AW60E. There are the following macros in one of the header files:

 

    #define _DEBUGT(a)   Debugt(a)    #define _DEBUGI(a)   Debugi(a)    #define _DEBUGC(a)   Debugc(a)    #define _DEBUGNL     Debugnl()

 

My question is, what is the point of making such a subsitution of function names for what looks like preprocessor directive names?

ラベル(1)
タグ(1)
0 件の賞賛
返信
1 解決策
1,439件の閲覧回数
bigmac
Specialist III

Hello irob,

 

In all probability the real macros were named with upper case and underscore, but one or more files used the same macros, but with the alternative naming.  The use of the header file would avoid the need to change every instance of the macro use within these files, or create a second set of macros with the different naming.

 

This practice is obviously not helpful in the understanding of the code operation, probably requiring the knowledge of the contents of two header files instead of one.

 

Regards,

Mac

 

元の投稿で解決策を見る

0 件の賞賛
返信
3 返答(返信)
1,440件の閲覧回数
bigmac
Specialist III

Hello irob,

 

In all probability the real macros were named with upper case and underscore, but one or more files used the same macros, but with the alternative naming.  The use of the header file would avoid the need to change every instance of the macro use within these files, or create a second set of macros with the different naming.

 

This practice is obviously not helpful in the understanding of the code operation, probably requiring the knowledge of the contents of two header files instead of one.

 

Regards,

Mac

 

0 件の賞賛
返信
1,439件の閲覧回数
irob
Contributor V
Your guess is as good as mine, bigmac. And you're indeed right -- tough to understand their code this way! I finally gave up trying and just did a find-n-replace in all their source, dumped the macros, and went about my business. With those preceding underscores, I was thinking it was some sort of directive use which through me. Like a bizarre compiler trick or something. Thanks for the help.
0 件の賞賛
返信
1,439件の閲覧回数
bigmac
Specialist III

Hello irob,

 

For C coding, keep in mind that the preprocessor handles the macros by simply providing text substitution, with the possibility of multiple substitutions if macros are included within macros.  You can always determine what final substitutions have been made by running the preprocessor alone for the project.  This can be a very useful debug tool.

 

Regards,

Mac

 

0 件の賞賛
返信