[SOLVED] Using #define value as parameter to printf

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • [SOLVED] Using #define value as parameter to printf

    Hi,

    I would like to print define value using printf, for example:

    #define MODULE_NAME MODULE1

    printf (MODULE_NAME);

    Is there any way to do so without adding commas to the test ("MODULE1")?

    Thanks,
    eyal.
  • By "commas" you mean "quotes" ?

    Remember that the preprocessor just does a simple text substitution

    So, for this to work, your #define must expand to something that would be valid as a printf argument.

    So, if you want MODULE_NAME to expand to a string, you will have to define it as such; eg,

    #define MODULE_NAME "MODULE1"

    Then you can put MODULE_NAME anywhere that a string literal would be legal.

    Note that this is standard 'C' stuff - nothing specific to Segger or SES