1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>

#define  TRIPLE(n)  ((n) * 3)
#define  print_int_expression(n)  ( printf("%s == %d\n", (#n), (n)) )
// This can ONLY be done with a #define function-like macro
// #n  is replaced with a string constant of whatever was passed for the parameter n.
// Do not add semicolon at the end of the replacement.  The semicolon will be added when
// the macro is used in the code (↓).

#define MULTIPLY(lhs, rhs)  ((lhs) * (rhs))

int main(int argc, char* argv[]) {
    //printf("TRIPLE(100) == %d\n",  TRIPLE(100));
    print_int_expression( TRIPLE(100) );
    // ⇒ ( printf("%s == %d\n", ("TRIPLE(100)"), (TRIPLE(100))) )

    print_int_expression( TRIPLE(100) + 500 );
    // ⇒ ( printf("%s == %d\n", ("TRIPLE(100) + 500"), (TRIPLE(100) + 500)) )

    print_int_expression( TRIPLE(100) + TRIPLE(1000) + 13 );
    // ⇒ ( printf("%s == %d\n", ("TRIPLE(100) + TRIPLE(1000) + 13"), (TRIPLE(100) + TRIPLE(1000) + 13)) )

    print_int_expression(MULTIPLY(4, 3));

    return EXIT_SUCCESS;
}
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */

© Copyright 2022 Alexander J. Quinn         This content is protected and may not be shared, uploaded, or distributed.