我创建了一个类似于经典 C 的数组(不是 NSArray 或其子数组之一) - 类似 BOOL i[5];
。我想让它的所有值都等于NO。
首先,我没有找到任何有关此类数组初始值的信息(我知道在经典 C 中它们将是未定义的,但不太了解 Objective-C。我找到了有关类及其内部数据的信息[分配后,无需初始化],但不涉及简单数据类型)。
第二,如果我应该手动设置数组值 - 我应该使用 memset(...); 还是不同的东西?
为了防止可能出现的问题...我想使用此构造作为临时布尔标志数组,并且不认为它被证明可以使用类似 NSArray 的东西。
I create an array, similar to classic C (not NSArray or one of it's children) - something like BOOL i[5];
. And I want to make all its values to be equal to NO.
First of all, I didn't found any information about initial values of such arrays (I know that in classic C they will be undefined, but don't know exactly about Objective-C. I found info about classes and its inner data [after allocation, without initialization], but not about simple data types).
And the second, if I should set array values manually - should I use memset(...);
or something different?
To prevent possible questions... I want to use this construction as array of temporary boolean flags and don't think that it is proved to use something like NSArray here.
发布评论
评论(2)
如果
BOOL i[5]
是 ObjC 类的 ivar,则其内容将被初始化 (memset
-ed) 为 0。如
+alloc
方法:要在其他情况下将数组设置为全否,您可以使用
If that
BOOL i[5]
is an ivar of an ObjC class, its content will be initialized (memset
-ed) to 0.As described in the
+alloc
method:To set the array to all NO in other situations, you could use
即使它是 0-ed 而不是像 C 中的 undef,正确的初始化也应该显式设置所有值,因为您无法知道 NO 是否为 0(它是,但假设......!),所以简单地说:
可以这样做工作。
Even if it is 0-ed instead of undef like in C, a proper initialization should set all values explicitly since you can't know if NO is 0 (it is, but hypotethically...!), so simply:
could do the job.