C 语言restrict 关键字的概念及使用例子

  restrict是c99标准引入的,它只可以用于限定和约束指针,
并表明指针是访问一个数据对象的唯一且初始的方式.即它告诉编译器,所有修改该指针所指向内存中内容的操作都必须通过该指针来修改,
而不能通过其它途径(其它变量或指针)来修改;这样做的好处是,能帮助编译器进行更好的优化代码,生成更有效率的汇编代码.
  C语言核心技术上有对它的详细应用:

void *memcpy( void * restrict dest , const void * restrict src, size_t n) 

  这里给出一个它的使用例子:

#include <stdio.h>

int main()
{

        short* __restrict__ ptest = (short*)malloc(16*sizeof(short));
        char* __restrict__ ctest = (char*)malloc(32*sizeof(char));

        for(int icnt =0 ; icnt < 32; icnt++)
        {
                ctest[icnt] = 0x55;
        }

        memcpy((unsigned int)ptest + 0,(unsigned int)ctest, 16);

        for(int cnt =0 ; cnt < 8; cnt++)
        {
                printf("cnt:%d data:%d 
",cnt,(unsigned int)ptest[cnt]);
        }

        printf("size:%d",sizeof(unsigned int));

        free(ptest);
        free(ctest);

        return 0;
}
~    

参考文档:

https://www.jb51.net/article/35607.htm

https://blog.csdn.net/u010129119/article/details/52789618

原文地址:https://www.cnblogs.com/dylancao/p/9732772.html