gpt4 book ai didi

c - Objective-C - SystemSoundID(typedef'd UInt32)是否自动分配为 0?

转载 作者:太空宇宙 更新时间:2023-11-04 00:33:41 25 4
gpt4 key购买 nike

- (void)playAlarmSound:(NSTimer *)theTimer {
static SystemSoundID soundID/* = 0 */; // ?
if (!soundID) {
soundID = [Utilities createSystemSoundIDFromFile:@"beep" ofType:@"caf"];
}
...
}

SystemSoundID(是一个UInt32)是否自动赋值0?还是我应该明确分配它?我必须这样做并测试它是否未被 Utilities 方法初始化,因为如果我只是执行 static SystemSoundID soundID = [Utilities createSystemSoundIDFromFile:@"beep"ofType:@ 它不会编译“咖啡馆”];。起初我尝试将它分配给 NULL,但后来我意识到它不是一个指针,所以不管怎样,我应该在那里有 = 0 还是它是多余的?

最佳答案

这道题不涉及任何objective-c特性,所以答案在c标准中。

C99,第 6.7.8 节,第 10 段:

If an object that has static storage duration is not initialized explicitly, then:

...

— if it has arithmetic type, it is initialized to (positive or unsigned) zero;

UInt32(它本身就是 uint32_t)是一种算术类型。因此,初始化为零。

关于c - Objective-C - SystemSoundID(typedef'd UInt32)是否自动分配为 0?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1507215/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com