是否可以以某种方式归档以下内容?我正在使用 gcc。
#define foo(argCount, ...)\
    FOR_EACH_IN_VA_ARGS_(argCount, element, __VA_ARGS__)\
    {\
        printf("%u", sizeof(element));\
    }
Run Code Online (Sandbox Code Playgroud)
感谢您的回答。
在尝试创建编译时哈希宏时,它可以工作,但有问题。所以我想如果字符串在编译时是已知的(它们是),整个散列应该被优化为一个常量。这个启用了优化级别 -O3 的 gcc C99 代码:
#include <stdio.h>
int main(void)
{
    char const *const string = "hello";
    int hash = 0;
    for (unsigned char i=0; i < sizeof string; ++i)
    {
        hash += string[i]; //reeaally simple hash :)
    }
    printf("%i", hash);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)
产生了以下汇编代码:
.LC0:
        .string "hello"
.LC1:
        .string "%i"
main:
        sub     rsp, 8
        movsx   eax, BYTE PTR .LC0[rip+6]
        movsx   edx, BYTE PTR .LC0[rip+7]
        mov     edi, OFFSET FLAT:.LC1
        lea     esi, [rax+532+rdx]
        xor     eax, eax
        call    printf
        xor     eax, eax …Run Code Online (Sandbox Code Playgroud)