preprocessor directives in macros

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

preprocessor directives in macros

跳至解决方案
2,168 次查看
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,435 次查看
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,436 次查看
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,435 次查看
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,435 次查看
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 项奖励
回复