如何创建指向结构的指针并对其进行类型转换?

发布于 2024-11-05 18:31:14 字数 1011 浏览 0 评论 0原文

有人可以告诉我我哪里出错了吗?我试图创建一个指向传递给函数的结构 aqData 的指针,并将其类型转换为 AQPlayerState 的结构类型。

我收到错误 - 使用未声明的标识符“AQPlayerState”和预期表达式

    @implementation AudioPlayer

#define kNumberBuffers 3

struct AQPlayerState {
    AudioStreamBasicDescription   mDataFormat;
    AudioQueueRef                 mQueue;
    AudioQueueBufferRef           mBuffers[kNumberBuffers];
    AudioFileID                   mAudioFile;
    UInt32                        bufferByteSize;
    SInt64                        mCurrentPacket;
    UInt32                        mNumPacketsToRead;
    AudioStreamPacketDescription  *mPacketDescs;
    bool                          mIsRunning;
};

static void HandleOutputBuffer (
                                void                *aqData,
                                AudioQueueRef       inAQ,
                                AudioQueueBufferRef inBuffer
                                ) {

    struct AQPlayerState *pAqData = (AQPlayerState *) aqData;

提前感谢您的帮助

can someone tell me where I'm going wrong here? I'm trying to create a pointer to the struct aqData that is passed in to the function, and type type cast it to a struct type of AQPlayerState.

I'm getting the errors - Use of undeclared identifier "AQPlayerState" and Expected expression

    @implementation AudioPlayer

#define kNumberBuffers 3

struct AQPlayerState {
    AudioStreamBasicDescription   mDataFormat;
    AudioQueueRef                 mQueue;
    AudioQueueBufferRef           mBuffers[kNumberBuffers];
    AudioFileID                   mAudioFile;
    UInt32                        bufferByteSize;
    SInt64                        mCurrentPacket;
    UInt32                        mNumPacketsToRead;
    AudioStreamPacketDescription  *mPacketDescs;
    bool                          mIsRunning;
};

static void HandleOutputBuffer (
                                void                *aqData,
                                AudioQueueRef       inAQ,
                                AudioQueueBufferRef inBuffer
                                ) {

    struct AQPlayerState *pAqData = (AQPlayerState *) aqData;

Thanks in advance for any help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泼猴你往哪里跑 2024-11-12 18:31:14

我相信Objective-C 的行为与C 相同。如果不是,这可能不适用于Objective-C

C 中的结构通过其“全名”进行识别。 尝试

    struct AQPlayerState *pAqData = (struct AQPlayerState *) aqData;

或者甚至更好,根本不施法。 C 编译器知道如何从 void* 转换为任何其他指向对象的指针

    struct AQPlayerState *pAqData = aqData;
  • 隐式转换:
  • 显式转换(强制转换):不太好

I believe Objective-C behaves as C. If it doesn't this might not apply to Objective-C.

structs in C are recognized by their "full name". Try

    struct AQPlayerState *pAqData = (struct AQPlayerState *) aqData;

or, even better, don't cast at all. The C compiler knows how to convert from void* to any other pointer to object

    struct AQPlayerState *pAqData = aqData;
  • implicit conversion: good
  • explicit conversion (cast): not so good
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文