Jump to content
Sign in to follow this  
Edward Mulder

#define Problem

Recommended Posts

Hi all,

 

I want to use a define when debugging my program. I have a UART routine that waits

for an interrupt. When debugging, I want to skip that line. The structure of my program

is like this:

 

main.c

 

#define DEBUG

#include "serial.h"

 

void main()

{

}

 

 

serial.c

 

void ser_printf(char value)

{

#ifdef DEBUG

return;

#endif

while ((txsta & 1 << TRMT) == 0) ;

txreg = value;

}

 

 

In the project part I have incuded the serial.c file, but now the problem:

the reference to DEBUG in the serial.c file does not "see" the DEBUG

declaration in the main.c file

 

What can I do to control the ser_printf function from the main file? I do

not want to make changes to the serial.c file every time I want to debug.

 

Thanks,

 

Edward

Share this post


Link to post
Share on other sites

We use defines extensively in system headers and preprocessor does its job well. Something else must couse this problem in your code. I suggest to inspect your preprocessed sources. By default compiler deletes preprocessed file during the compilation. You need to do 2 extra steps to get it. Run the compiler with -v command line option. This will print the preprocessor command line in the compiler output. It will look something like:

 

"C:\Program Files\SourceBoost\pp.exe" C:\_\test.c -i "C:\Program Files\SourceBoost\include" -d _PIC16F648A -la -c2 -o test.pp -v -d _BOOSTC -d _PIC16

 

Use this command line to manually run preprocessor and this will produce a .pp file out of your .c file. This is the preprocessed file that compiler uses to generate code.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

Edward, what you really want to do is:

 

global.h

 

#define DEBUG

 

main.c

#include "global.h"

#include "serial.h"

 

void main()

{

}

 

 

serial.c

 

#include "global.h"

 

void ser_printf(char value)

{

#ifdef DEBUG

return;

#endif

while ((txsta & 1 << TRMT) == 0) ;

txreg = value;

}

 

By including the global.h in ALL of your .c files you effectively copy it's content into each of them, so the DEBUG define (and anything else you care to put in there) is available to each source file in your project.

 

Then you can modify global.h to add or remove the DEBUG define as appropriate, and the change will be incorporated into all your source files.

 

 

richard.

Edited by richard_s

Share this post


Link to post
Share on other sites

@Pavel:

 

I did as you said, but what do I have to look for? All I see is a line that contains only comment

in the .pp file, it does not make any difference when I use #define DEBUG 1 or 0. What should the output look like?

 

@richard:

 

Using a global.h file surely helps, but the problem is that I should declare it always, even if I don't

want to use the DEBUG. When I don't declare the global.h file, the compiler generates an error.

 

Any suggestions?

 

Thanks to both of you.

 

Edward

Share this post


Link to post
Share on other sites

Either use #define DEBUG in a header file that is included into all your source files or use compiler -d command line option.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...