zoukankan      html  css  js  c++  java
  • pragma警告处理

    使用pragma消除警告 (绝不可强行消除,因为有可能是个运行时错误)
    #pragma clang diagnostic push
    #pragma clang diagnostic ignored "命令字符串"
        代码块
    #pragma clang diagnostic pop
    
    1. "-Warc-performSelector-leaks" performselector可能造成内存泄漏
        SEL sel = @selector(gl_getImage:);
        [self performSelector:sel withObject:nil];
        以上警告也可使用消除
        IMP imp = [app methodForSelector:sel];
        void (*func)(id , SEL ,NSInteger) = (void *)imp;
        func(app,selector,0);
    
    2. "-Wreceiver-is-weak" 调用者接收者是weak属性
    
    3. "-Wunused-variable" 变量未使用
        或者 __unused int m = 2; //Unused variable 'm'
    
    4. "-Wdeprecated-declarations" 方法弃用
        [UIAlertView alertView........]
    
    5. "-Warc-retain-cycles" 循环引用
        while(true){}
    
    6. "-Wincompatible-pointer-types" 指针不兼容的
    
    7. "-Wundeclared-selector" 方法在本类中未申明
       eg. SEL sel = @selector(gl_getImage)
       不过以上方法导致的警告也可使用runtime机制消除
           SEL sel = sel_registerName("gl_getImage:")
           SEL sel = NSSelectorFromString(@"gl_getImage:");
    8. "-Wunreachable-code" 代码将永不被执行
        NSLog(@"m");
        return;
        NSLog(@"n"); //Code will never be executed
    
    
    如果想将项目中所有某类型的警告都消除
    11. 配置文件 buildSettings->Other Warning Flags
        加入配置字符
        11.1 code will never be executed
            -Wno-unreachable-code   全局禁用警告
            -Wunreachable-code      全局启用警告
        11.2 Unused Entity Issue / unused function 'xxxxx'
            -Wno-unused-function    全局禁用
            -Wunused-function       全局启用
        11.3 ......
    
  • 相关阅读:
    iOS:网络检测
    WinJS:设置listView垂直滚动
    iOS:在AppDelegate中定义managed object context
    简笔画项目总结: ios绘图机制 & 实现记录笔迹功能
    CSS基础
    DOM小结
    iOS:view.frame
    WP:初探
    iOS:UIWebView scrollView 的分页滑动问题
    Mono for Android: 利用mono for android开发的第一个程序
  • 原文地址:https://www.cnblogs.com/gulong/p/10283618.html
Copyright © 2011-2022 走看看