Preprocessor Directives

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi

I'm trying to show a message in the compiler window of AVRstudio4 (+winavr).
So far I have only managed to do it using # warning (and # error which stops the compilation)

#ifdef (something)
  # warning "show message"
#endif

I have read about # message and # print but they are not working, any idea of an alternative I can use?

I would also like to ask if it is possible to show the defined value somehow, for example

#ifdef (something)
  #define my_message show1
#else
  #define my_message show2
#endif

is it possible to show the defined value of my_message in the compile window?

Thank you
Alex

"For every effect there is a root cause. Find and address the root cause rather than try to fix the effect, as there is no end to the latter."
Author Unknown

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For the first I think #warning is as good as it's going to get,

For the second:

avr-gcc -mmcu=atmega16 -E -dM test.c | grep my_message

The key things here being -E which means pre-preocess only and -dM which means dump all the macro definitions. If you don't use the pipe to grep be ready for a lot of output ;-)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The syntax of #ifdef is a bit fussy.
I prefer the defined() operator e.g.

#if defined(FOO) || !defined(BAR) || ARITH_VALUE

In theory, #warning cannot show the macro expansion.
Some pre-processors might give you an expansion.

In practice you know what conditions you desire in a conditional expression. So you might just use

#warning "literal string message"

Some extensions are non-standard. Life is much easier if you stick to standard conventions.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you for your replies.

david.prentice wrote:
The syntax of #ifdef is a bit fussy.
I prefer the defined() operator e.g.

Yes I use that too when I have multiple expressions like

#if defined (__AVR_ATmega48__) | defined (__AVR_ATmega88__) | defined (__AVR_ATmega168__) | defined (__AVR_ATmega48P__) | defined (__AVR_ATmega88P__)

clawson wrote:
The key things here being -E which means pre-preocess only and -dM which means dump all the macro definitions. If you don't use the pipe to grep be ready for a lot of output

I was able to add -E and -dM in the compiler parameters window of avrstudio, I get the huge list as you said which includes my define but I have no idea how to apply grep through a pipe to filter the result, is it possible only through command line?

Alex

"For every effect there is a root cause. Find and address the root cause rather than try to fix the effect, as there is no end to the latter."
Author Unknown

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

I was able to add -E and -dM in the compiler parameters window of avrstudio, I get the huge list as you said which includes my define but I have no idea how to apply grep through a pipe to filter the result, is it possible only through command line?


I'm the other way round - I haven't a clue how you do this kind of stuff inside an IDE which is why I generally build at the command line. There's probably an age split around the 25-30 year old mark where programmers prefer CLI or GUI. I am well on the upper side of that line so I prefer CLI ;-)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It would be nice to hear some tricks from a 20 yr old that understands IDEs and GUIs.

Using standard Unix command line tools is very powerful.

I can't see how you could harness this power in a GUI. I suppose you can have a series of dialogs that represent each stage in a pipeline, but it sounds very messy.

The only 'common' implementation is 'Search through whole project'. Marginally easier in the GUI than the equivalent command line. (Mind you, you could put the complex command(s) in a script)

David.