Search code examples
c++c-preprocessorpreprocessor-directive

can anyone explain how the "->" is implemented in the #define


I'm working on a reference design with this line as a #define

#define MEDIA_EXT_STATE "\"adv7611 12-004c\":1 -> \"40080000.tpg\":0[%d]"

The sprintf function uses it which is then passed to the media_parse_setup_links() function.

sprintf(media_formats, MEDIA_EXT_STATE, 1);
ret = media_parse_setup_links(media, media_formats);

Solution

  • The macro defines MEDIA_EXT_STATE as a string literal, similar as

    #define FOOBAR "foo -> bar"
    

    defines FOOBAR as the string literal "foo -> bar". Maybe you got confused by the escaped ", but thats just like with ordinary string literals:

    std::cout << "\"123";
    

    prints "123.

    To know what is the meaning of the -> in the string, you'd have to look into the implementation of media_parse_setup_links or read the documentation.