• MISRA C:2012 Dir-1.1(只记录常犯的错误和常用的规则)Bit-fields inlineC99,NOT support in C90 #pragma


    0202 转义字符‘[]’中的‘-’是执行时定义的。不要这么用。

    #include <stdio.h>
    
    extern void foo(char *cptr)
    {
        scanf("Total %[a-z]", cptr);                /* Message 0202 */
    }

    https://stackoverflow.com/questions/19569545/how-to-use-scanf-to-input-specific-letter

    The problem is, most likely, that you do not check for errors, and print the string even when the scanf call fails.

    With the pattern "%[A-Z]" you only scan for uppercase letters, and if the string you input doesn't begin with upper case letters scan will fail. This of course means that the string input will never be filled, and will contain random data which you then print.

    I recommend you read e.g. this reference. It will tell you that the function will return the number of items successfully scanned, which should be 1 in your case. If the scanf function in your code doesn't return 1 then there is a problem.

    So you need to do something like

    if (scanf(...) == 1)
        printf(...);
    else
        printf("Something went wrong when reading input
    ");

    0320 在for语句中声明

    extern void foo(void)
    {
        for (int i = 0; i < 10; ++i)           /* Message 0320 and also 3220 */
        {
    
        }
    }

    0604  声明出现在复合语句中的语句之后

    extern void foo(void)
    {
      int i;
    
      i = 1;
    
      float f;                /* Message 0604 */
    
      f = 2.5F;
    
    }
    extern void foo(void)
    {
      int i;
    
      float f;             
      i = 1;
    
      f = 2.5F;
    
    }

    0612 Size of object '%s' exceeds 32767 bytes - program does not conform strictly to ISO:C90.

    char x[40][1000];         /* Message 0612 */

    0930 Trailing comma at the end of an enumerator-list. 枚举列表末尾的逗号。

    enum ED { ZERO=0, TWO=2, FOUR=4, };         /* Message 0930 */

    1031 Initializer for 'struct', 'union' or array type is not a constant expression.

    struct ST {int a; int b;};
    
    extern void foo(int p1, int p2, int p3)
    {
        int var = p1;                         /* Scalar object - OK */
    
        int buf1[] = {1, 2, 3};
    
        int buf2[3]= {p1, p2, p3};            /* Message 1031 */
    
        struct ST sx = {p1, p2};              /* Message 1031 */
    }
    Constant Expressions
    Constant expressions may never contain (except as an operand to the sizeof operator):
    
    Assignment operators
    Increment or decrement operators
    Comma operators
    Function calls
    Integral constant expressions
    ... are used in case expressions, to specify array bounds, to specify the size of a bit-field and as enumerator constants.
    
    They may contain:
    
    Integral constants
    Enum constants
    Character constants
    sizeof expressions
    Floating constants cast to an integer type
    ... but may not contain (except as an argument to the sizeof operator):
    
    Arrays
    * operator
    & operator
    Structure member operations

    1053 在此初始化列表中使用了标识符

    int arr[40] = { [0] = 1, [10] = 2, [30] = 3 };          /* Message 1053 */

    1054 A compound literal has been used.

    struct ST { int im; float fm; };
    
    extern struct ST stx;
    
    void foo(void)
    {
        stx = (struct ST) {45, 1.23F};              /* Message 1054 */
    }

    1055 The keyword 'inline' has been used.

    static inline int foo(int a, int b)     /* Message 1055 */
    {
        return (a * 10) + b;
    }

    3116 Unrecognized #pragma arguments '%s' This #pragma directive has been ignored.

     




  • 相关阅读:
    页面抛出的"Unable to validate data"错误
    oracle的sqlnet.ora,tnsnames.ora,listener.ora三个配置文件 water
    Win7下完全卸载Oracle 11g water
    抛出多个异常 water
    【转】有关Oracle随机字符串的生成方法及具体应用 water
    【转】oracle 中随机取一条记录的两种方法 water
    【转】Oracle索引列NULL值引发执行计划该表的测试示例 water
    Oracle 取随机数 water
    dbms_output.put_line长度限制问题 water
    oracle 监听启动、停止、查看命令 water
  • 原文地址:https://www.cnblogs.com/focus-z/p/11919743.html
Copyright © 2020-2023  润新知