常量对象的数组常量 [英] Constant array of constant objects

查看:123
本文介绍了常量对象的数组常量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在C(不是C ++)?

How do you define constant array of constant objects in C (not C++)?

我可以定义

int const Array [] = {
    /* init data here */
};

但这是恒定的对象的非恒定阵列

but that is a non-constant array of constant objects.

我可以使用

int const * const Array = {
    /* init data here */
};

和它可能会工作。
但有可能与数组语法做到这一点? (看起来更干净)

and it would probably work. But is it possible do this with array syntax? (Which looks more clean)

推荐答案

这是数组不能是恒 - 那是什么,甚至什么意思?数组大小已经是在任何情况下编译时间常数,如果所有成员都是常量,那么你想要做什么?什么样的变异是你想排除是可能的 const int的[]

An array cannot be "constant" -- what is that even supposed to mean? The array size is already a compile-time constant in any case, and if all the members are constants, then what else do you want? What sort of mutation are you trying to rule out that is possible for a const int[]?

这篇关于常量对象的数组常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆