Help understanding this Macro

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Affan Syed

    #1

    Help understanding this Macro

    Hi,
    I have done a lot of user space coding in C, which doesnt really need me to
    understand the following MACRO:

    #define UARTOutput(__x, __y,__args...) do { \
    static char __s[] PROGMEM = __y; \
    if (debug_out) \
    printf_P(__s, ## __args); \
    } while (0)

    So now what exactly is happening over here?
    Does double underscore do something special? Basically i can see that it is
    used as outputting a string to the UART like this
    UARTOutput(DBG, "%s", buf);

    So it just outputs the string in buf to the UART... but how (Assume that the
    UART is somehow initialized.. how is it even going to the UART!!!

    Thanks..
    Affan


  • Jogi Kuenstner

    #2
    Re: Help understanding this Macro

    Affan Syed wrote:
    [color=blue]
    > [...]
    > So it just outputs the string in buf to the UART... but how (Assume that
    > the UART is somehow initialized.. how is it even going to the UART!!![/color]

    Through the function printf_P ?
    The only solution I can imagine...

    Jogi

    --
    The particular mistake will not be repeated. There are plenty of
    mistakes left that have not yet been used.          A. Tanenbaum  
    JogiKue@kuenstn er.de

    Comment

    • Walter Roberson

      #3
      Re: Help understanding this Macro

      In article <cvba00$t89$1@g ist.usc.edu>, Affan Syed <asyed@usc.ed u> wrote:
      :I have done a lot of user space coding in C, which doesnt really need me to
      :understand the following MACRO:

      : #define UARTOutput(__x, __y,__args...) do { \
      : static char __s[] PROGMEM = __y; \
      : if (debug_out) \
      : printf_P(__s, ## __args); \
      : } while (0)

      :So now what exactly is happening over here?

      We can't tell -- you haven't told us anything about printf_P(), which
      is not a standard C routine.

      :Does double underscore do something special?

      The standard reserves __ followed by an upper-case letter
      for future and implimentation enhancements, but otherwise NO.

      :So it just outputs the string in buf to the UART... but how

      printf_P is sending it there.
      --
      Warhol's Law: every Usenet user is entitled to his or her very own
      fifteen minutes of flame -- The Squoire

      Comment

      Working...