You can't readily do it with a macro.
The problem is that a macro is a compile time construct, and the loop you have there is a run time construct; you can't do it directly.
You could investigate Boost Preprocessor (which is not specifically for C++; it also works with the C preprocessor) and use that to write macros which generate the loop.
You could hand unroll the loop and use a macro with a constant argument:
#define SATA_PORT(i) "/sata-ahci/port" #i
printf("%s\n", 0, SATA_PORT(0));
printf("%s\n", 1, SATA_PORT(1));
printf("%s\n", 2, SATA_PORT(2));
printf("%s\n", 3, SATA_PORT(3));
printf("%s\n", 4, SATA_PORT(4));
printf("%s\n", 5, SATA_PORT(5));
Or you can use an array of strings (also suggested by a now-deleted answer).
#define DIM(x) (sizeof(x)/sizeof(*(x)))
const char * const sata_ports[] =
{
"/sata-ahci/port0",
"/sata-ahci/port1",
"/sata-ahci/port2",
"/sata-ahci/port3",
"/sata-ahci/port4",
"/sata-ahci/port5"
};
for (int i = 0; i < DIM(sata_ports); i++)
printf("%d %s\n", i, sata_ports[i]);