【问题标题】:static with (void)静态与(无效)
【发布时间】:2013-01-29 10:05:18
【问题描述】:

这是苹果代码的一部分。

我不明白第一行。为什么有一个“无效”的回报?

// forward declaration of our utility functions
static NSUInteger _ImageCount(void);

static NSUInteger _ImageCount(void)
{
    static NSUInteger count = 0;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        count = [_ImageData() count];
    });
return count;
}

【问题讨论】:

  • 第一个声明只是一个函数原型。声明/定义的void 部分只是声明没有函数参数。返回类型为NSUInteger
  • 你是对的。我曾经在行首看到“void”。

标签: ios static void


【解决方案1】:

foo(void) 表示该函数不需要任何参数。但它确实返回和NSUInteger

static NSUInteger _ImageCount(void)
^      ^          ^           ^
|      |          |           parameter list
|      |          function name
|      return type
visibility (may be referenced only from this module)

【讨论】:

  • 静态 NSUInteger _ImageCount 好吗?还是每次没有参数时我都应该添加“(void)”?
【解决方案2】:

我认为你错误地构思了函数,因为函数应该返回“NSUInteger”。

“void”是来自c/c++的参数类型,表示“无参数”。

静态 NSUInteger _ImageCount(void);

“NSUInteger”是返回类型“void”指定无参数

【讨论】:

  • 是的,我倒置了“空白”位置(在我的脑海中)。它改变了意味着 Binyamin Sharet 像你一样对它做出了很好的解释。
猜你喜欢
  • 2020-09-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-01
  • 1970-01-01
相关资源
最近更新 更多