0

I am new to C, what exactly does #algo do here?

#define run(algo) execute(&algo, #algo)

In the function definition of execute it looks like it's somehow used for constant parameters ...

void execute(int (*algo_func)(int *, int, int), const char * algo_name)
{
    int hit = 0, miss = 0;

...

I found this here at line 408: https://github.com/scandum/binary_search/blob/master/binary-search.c

Jabberwocky
  • 48,281
  • 17
  • 65
  • 115
Dominik K
  • 399
  • 3
  • 9

1 Answers1

3

It's a preprocessor stringizing operator. The preprocessor replaces #algo with whatever was passed to the run() macro converted to a string literal, so:

run(some_algorithm)

would be changed to:

execute(&some_algorithm, "some_algorithm")
Maciej Stachowski
  • 1,708
  • 10
  • 19