C 将常量数据保存在一个位置

C 将常量数据保存在一个位置,c,C,我需要在我的C项目中存储关键字。现在我得写了 const char firstThingKeyword[] = "foofoofoofoo" const char secondThingKeyword[] = "barbarbarbar" 这些名字很长,所以我宁愿引用它们 keywords.firstThing 在普通C中有什么方法可以做到这一点吗?可能是GCC扩展 我考虑使用一个结构体,但在离开C++舒适区时,我做任何事情都有困难。 这里有一个使用结构: 使用结构?既然这些是常数,也许最好

我需要在我的C项目中存储关键字。现在我得写了

const char firstThingKeyword[] = "foofoofoofoo"
const char secondThingKeyword[] = "barbarbarbar"
这些名字很长,所以我宁愿引用它们

keywords.firstThing
在普通C中有什么方法可以做到这一点吗?可能是GCC扩展


我考虑使用一个结构体,但在离开C++舒适区时,我做任何事情都有困难。

这里有一个使用结构:
使用结构?既然这些是常数,也许最好使用一个定义“@埃弗特I”关于结构的思想,但是只在C++中编程而不是C,这对我来说有点麻烦。呃,是不是关键字。第一件事比第一件事关键字长?如果这就是它们需要多长时间才能有一个清晰的含义,那么把它们缩短会让它们变得不那么清晰。我怀疑这个结构也应该是const。所有大写名称只能用于宏或枚举常量。
#include <stdio.h>
#include <stdlib.h>

struct _keywords {
    const char *first;
    const char *second;
};

const struct _keywords Keywords = {
    .first = "AAA",
    .second = "BBB"
};

int main(void) {

    printf("first: %s\n", Keywords.first);
    printf("second: %s\n", Keywords.second);

    return 0;
}