Search code examples
cmacroswrapperreadability

use macros for arguments


I am trying to create a macro wrapper around a function so I could make the code more intuitive on reading. Something like instead of calling send_message_to_destination(m, d) to write send(m)to(d).

#include <stdio.h>

void send_data_to(int data, int dest)
{
    printf("Send %d to %d\n", data, dest);
}


#define send(data)to(destination) send_data_to(data, destination) 

int main() {

    int data = 5;
    int dest = 10;

    send(data)to(dest);
}

It is possible to do so? Do you think this would makes the code more readable or intuitive ?


Solution

  • I agree with the comments (not a good idea), however, you can use something like this. Remember the pre-processor just does a text replace with your macros.

    #define to(destination) destination)
    #define send(data) send_data_to(data,