相关疑难解决方法(0)

受限制的指针问题

关于限制指针的规则,我有点困惑.也许有人可以帮助我.

  1. 定义嵌套的受限指针是否合法,如下所示:

    int* restrict a;
    int* restrict b;
    
    
    a = malloc(sizeof(int));
    
    
    // b = a; <-- assignment here is illegal, needs to happen in child block
    // *b = rand();
    
    
    while(1)
    {
        b = a;  // Is this legal?  Assuming 'b' is not modified outside the while() block
        *b = rand();
    }
    
    Run Code Online (Sandbox Code Playgroud)
  2. 导出受限指针值是否合法,如下所示:

    int* restrict c;
    int* restrict d;
    
    
    c = malloc(sizeof(int*)*101);
    d = c;
    
    
    for(int i = 0; i < 100; i++)
    {
        *d = i;
        d++;
    }
    
    
    c …
    Run Code Online (Sandbox Code Playgroud)

c pointers c99 restrict-qualifier

5
推荐指数
1
解决办法
4054
查看次数

标签 统计

c ×1

c99 ×1

pointers ×1

restrict-qualifier ×1