preprocessor directives in macros

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

preprocessor directives in macros

Jump to solution
2,139 Views
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?

Labels (1)
Tags (1)
0 Kudos
Reply
1 Solution
1,406 Views
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

 

View solution in original post

0 Kudos
Reply
3 Replies
1,407 Views
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 Kudos
Reply
1,406 Views
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 Kudos
Reply
1,406 Views
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 Kudos
Reply