HISE Logo Forum
    • Categories
    • Register
    • Login

    Can #define preprocessor take parameters?

    Scheduled Pinned Locked Moved Scripting
    2 Posts 1 Posters 132 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      aaronventure
      last edited by aaronventure

      Setting

      #define PRINT(a) Console.print(#a)
      

      and then calling PRINT(hello) or PRINT("hello") returns "macro parameter amount mismatch". I feel like this is telling me that there's a parameter where it shouldn't be. Am I right?

      Docs point to this page https://www.tutorialspoint.com/cprogramming/c_preprocessors.htm but otherwise don't provide examples on using #define in HISE.

      I'm still getting the hang of HISEScript so please let me know if I missed something.

      1 Reply Last reply Reply Quote 0
      • A
        aaronventure
        last edited by

        Alright,

        #define DECLARE_REG(name) reg name
        DECLARE_REG(test) = 5.767;
        

        works as expected. No space between identifier and open parenthesis, got it.


        This compiles in C and prints the value, with the variable test_heyhey properly formed from two tokens.

        int main()
        {
            #define DECLARE_REG(name) int name ## _heyhey
            DECLARE_REG(test) = 69;
            
            printf("%d", test_heyhey);
        
            return 0;
        }
        

        When I try this in HISE, I try

        #define DECLARE_REG(name) reg name ## _heyhey
        DECLARE_REG(test2) = 69.6969;
        

        and get an error saying "Unexpected character '#' in source"

        How to do #define token concatenation in HISEScript, then? @Christoph-Hart

        1 Reply Last reply Reply Quote 0
        • First post
          Last post

        49

        Online

        1.7k

        Users

        11.7k

        Topics

        102.1k

        Posts