expected ';' at the end of declaration list

和自甴很熟 提交于 2019-12-11 20:14:40

问题


error:- expected ';' at the end of the declaration list
#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
{
    float number;                   error:- expected ';' at the end of the declaration list
    float result;
    int currentoperation;
    __weak IBOutlet UILabel *label;
}

- (IBAction)canceloperation:(id)sender;
- (IBAction)cancelnumber:(id)sender;
- (IBAction)buttonoperation:(id)sender;
- (IBAction)buttonnumber:(id)sender;


@end

Please fix this code.


回答1:


The OP's question is stated quite bad, but there is a genuine problem here.

The problem occurs when Xcode C Language Dialect is set to C99 instead of GNU99. C99 does not have a declaration for typeof(), and will assume it returns int. Then, the following bunch of confusing error messages are logged:

warning: type specifier missing, defaults to 'int'
  __weak typeof(self) weakSelf = self;
  ~~~~~~ ^
'__weak' only applies to Objective-C object or block pointer types; type here is 'int'
  __weak typeof(self) weakSelf = self;
  ^
a parameter list without types is only allowed in a function definition
  __weak typeof(self) weakSelf = self;
                ^
expected ';' at end of declaration
  __weak typeof(self) weakSelf = self;
                     ^

To change this: open the Project Navigator > click the project > click the target > Select the C Language Dialect > Hit backspace to set the default value.




回答2:


This is a duplicate of the many "invisible character" questions. You have an invisible character in your code.

If you have a history of using emacs or using the ctrl key, you could easily have tapped ctrl-return and inserted an invisible character.

http://www.friday.com/bbum/2012/12/23/xcode-sometimes-a-return-is-not-a-return-emacs-brain-damage/



来源:https://stackoverflow.com/questions/16999749/expected-at-the-end-of-declaration-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!