CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  C/C++ >  C语言

C语言中有个类型限定符restrict,谁能解释下这个限定符的含义!

楼主piaozi2003()2005-12-12 13:46:35 在 C/C++ / C语言 提问

如题 问题点数:50、回复次数:12Top

1 楼piaozi2003()回复于 2005-12-12 13:52:58 得分 0

自己先顶!Top

2 楼improgrammer(无忌)回复于 2005-12-12 14:08:06 得分 0

答案是:标准C语言没有这个关键字。Top

3 楼happy__888([顾问团]寻开心 www.e-jjj.com)回复于 2005-12-12 14:08:58 得分 0

没有听说这个关键字  
  不是标准cdTop

4 楼piaozi2003()回复于 2005-12-12 14:24:43 得分 0

有这个呀Top

5 楼piaozi2003()回复于 2005-12-12 14:27:14 得分 0

在UNIX下的strtok函数原型是  
   
  char*   strtok(char*   restrick   s1,   const   char*   restrict   s2)Top

6 楼megaboy(飞天御剑流之杀神一刀斩)回复于 2005-12-12 14:30:13 得分 20

restrict关键字从C99才开始支持,C89是没有的:  
   
   
  6.7.3   Type   qualifiers  
   
  Syntax  
   
  type-qualifier:  
  const  
  restrict  
  volatile  
   
  Constraints  
  Types   other   than   pointer   types   derived   from   object   or   incomplete   types   shall   not   be  
  restrict-qualified.Top

7 楼piaozi2003()回复于 2005-12-12 14:31:55 得分 0

我在网上只查到这么点资料  
   
  关键字restrict用来消除数据间的相关性,编译器从而可以安排语句的并行执行;  
   
  但不是很理解,所以在这里请教!而且我在网络上查到好多C语言的书中目录中都有  
  关于restrict的介绍,所以谁知道的话请说说Top

8 楼megaboy(飞天御剑流之杀神一刀斩)回复于 2005-12-12 14:35:34 得分 0

restrict表示只能通过它限定的指针访问该指针所指向的对象。Top

9 楼megaboy(飞天御剑流之杀神一刀斩)回复于 2005-12-12 14:38:33 得分 0

7   An   object   that   is   accessed   through   a   restrict-qualified   pointer   has   a   special   association   with   that   pointer.   This   association,   defined   in   6.7.3.1   below,   requires   that   all   accesses   to   that   object   use,   directly   or   indirectly,   the   value   of   that   particular   pointer.   The   intended   use   of   the   restrict   qualifier   (like   the   register   storage   class)   is   to   promote   optimization,   and   deleting   all   instances   of   the   qualifier   from   all   preprocessing   translation   units   composing   a   conforming   program   does   not   change   its   meaning   (i.e.,   observable   behavior).Top

10 楼wanguodu(足文字D)回复于 2005-12-12 16:19:34 得分 30

看看TI的帮助:  
  To   help   the   compiler   determine   memory   dependencies,   you   can   qualify   a   pointer,   reference,   or   array   with   the   restrict   keyword.   The   restrict   keyword   is   a   type   qualifier   that   may   be   applied   to   pointers,   references,   and   arrays.   Its   use   represents   a   guarantee   by   the   programmer   that   within   the   scope   of   the   pointer   declaration   the   object   pointed   to   can   be   accessed   only   by   that   pointer.   Any   violation   of   this   guarantee   renders   the   program   undefined.   This   practice   helps   the   compiler   optimize   certain   sections   of   code   because   aliasing   information   can   be   more   easily   determined.  
   
  In   the   example   that   follows,   the   restrict   keyword   is   used   to   tell   the   compiler   that   the   function   func1   is   never   called   with   the   pointers   a   and   b   pointing   to   objects   that   overlap   in   memory.   You   are   promising   that   accesses   through   a   and   b   will   never   conflict;   this   means   that   a   write   through   one   pointer   cannot   affect   a   read   from   any   other   pointer.   The   precise   semantics   of   the   restrict   keyword   are   described   in   the   1999   version   of   the   ISO   C   standard.  
   
  Use   of   the   restrict   type   qualifier   with   pointers  
   
  void   func1(int   *   restrict   a,   int   *   restrict   b)  
  {  
      /*   func1's   code   here   */  
  }  
   
  This   example   illustrates   using   the   restrict   keyword   when   passing   arrays   to   a   function.   Here,   the   arrays   c   and   d   should   not   overlap,   nor   should   c   and   d   point   to   the   same   array.  
  Use   of   the   restrict   type   qualifier   with   arrays  
   
  void   func2(int   c[restrict],   int   d[restrict])  
  {  
      int   i;  
   
      for(i   =   0;   i   <   64;   i++)  
      {  
          c[i]   +=   d[i];  
          d[i]   +=   1;  
      }  
  }Top

11 楼zcz0918()回复于 2005-12-12 17:19:30 得分 0

C99不通用  
  至少偶没用过也没见过Top

12 楼piaozi2003()回复于 2005-12-13 13:34:05 得分 0

OK!谢谢Top

相关问题

  • 关于Const限定符
  • 关于const限定符
  • 编译错误:无效限定符 是什么错误?
  • 帮忙解决“无效限定符”错误!
  • c# 中new 的含义
  • warning C4278: “TranslateAccelerator”: 类型库“mshtml.tlb”中的标识符已经是宏;使用“rename”限定符
  • c语言中'#'号是什么含义
  • [求助]System.Data.SyntaxErrorException: 聚合参数中的语法错误: 需要具有可能的“Child”限定符的单个列参数。
  • C, C++, Java函数(方法)前面加Static关键字含义有何区别?
  • 大家进来说说c、c++、vc、vc++的具体含义与区别(新手)

关键词

  • restrict
  • qualifier
  • 关键字
  • 语言
  • pointer
  • accessed
  • object
  • char
  • type

得分解答快速导航

  • 帖主:piaozi2003
  • megaboy
  • wanguodu

相关链接

  • C/C++ Blog
  • C/C++类图书
  • C/C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo