Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expected ; after top level declarator, error in xcode

Tags:

c++

c

xcode

I am working with this utils.c file in xcode, which has the following:

 #if FF_API_AVCODEC_OPEN
    int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec)
    {
        return avcodec_open2(avctx, codec, NULL);
    }

It's causing an Expected ; after top level declarator, error (during build) in xcode at this line: int attribute_align_arg avcodec_open(....

Why? and what should I do to resolve this.

Thank you.

like image 342
cube Avatar asked Jun 16 '13 02:06

cube


2 Answers

I ran into this error when using the auto completion.

When inserting the parameter of a function, XCode will insert placeholders that need to be edited but show as completely valid C++ in the GUI.

It took me some hours until I checked my file in another editor, revealing that instead of the expected:

void func(int a)

XCode had actually inserted

void func(<#int a#>)

In the XCode editor the parameter shows as int a with a light blue background, so it isn't easy to spot as the source of the compiler error.

like image 65
Zord Avatar answered Sep 28 '22 08:09

Zord


I got a similar error in xcode for the following code:

#ifndef Parser_hpp
#define Parser_hpp

#include <string>
std::string getTitle();

#endif /* Parser_hpp */

The reason was that the code had to be wrapped with C++ preprocessor directives. Like so:

#ifndef Parser_hpp
#define Parser_hpp
#if defined __cplusplus

#include <string>
std::string getTitle();

#endif /* __cplusplus */
#endif /* Parser_hpp */
like image 25
Prateek Sharma Avatar answered Sep 27 '22 08:09

Prateek Sharma