【问题标题】:Xcode cannot find label 'error' for PortAudioXcode 找不到 PortAudio 的标签“错误”
【发布时间】:2019-03-29 00:02:26
【问题描述】:

我正在尝试按照Initialising PortAudio tutorial 中的说明初始化 portaudio。

它说要检查初始化过程中是否有错误,如下所示:

PaError err = Pa_Initialize();
if (err != paNoError) goto error;

这是我使用的确切代码。

我在 OS X Mojave 10.14.4 上运行它,使用 Xcode 10.1 和 10.12 OS X SDK。

我试图在 PortAudio 文档中查找错误标签的位置无济于事,并且名为 error 的文件中没有变量。

到目前为止的完整程序是:

# include <iostream>
# include "portaudio.h"
using namespace std;

// Typedef and demo callbacks here.

int main(int argc, const char * argv[])
{
    PaError err = Pa_Initialize();

    if (err != paNoError) goto error;

    // Nothing here yet.

    err = Pa_Terminate();

    if (err != paNoError)
    {
        printf("Port audio error terminating: %s", Pa_GetErrorText(err));
    }
    return 0;
}

据我在教程中可以看出,这应该是一个有效的语句,但 Xcode 显示语法错误: Use of undeclared label 'error'

【问题讨论】:

    标签: c++ xcode portaudio


    【解决方案1】:

    检查c++ reference for goto statementsan example program for PortAudio,问题来自假设goto 可以访问portaudio.h 文件中定义的内容,但事实并非如此。

    如果您遇到此问题,我假设您也不熟悉 goto 语句。

    本教程假定主函数中有一部分专门用于解决错误。为了解决这个问题,我们需要在我们的main 函数中定义一个错误标签来负责响应错误。

    例如:

    int main(void) {
        PaError err;
    
        // Checking for errors like in the question code, including goto statement.
    
        return 1; // If everything above this goes well, we return success.
    
    error:               // Tells the program where to go in the goto statement.
        Pa_Terminate();  // Stop port audio. Important!
        fprintf( stderr, "We got an error: %s/n", Pa_GetErrorMessage(err));
        return err;    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-27
      • 1970-01-01
      • 2020-08-20
      • 1970-01-01
      • 2017-11-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多