JavaScript is required to for searching.
跳过导航链接
退出打印视图
Oracle Solaris Studio 12.3:C 用户指南     Oracle Solaris Studio 12.3 Information Library (简体中文)
search filter icon
search icon

文档信息

前言

1.  C 编译器介绍

2.  特定于 C 编译器实现的信息

2.1 常量

2.1.1 整型常量

2.1.2 字符常量

2.2 链接程序作用域说明符

2.3 线程局部存储说明符

2.4 浮点,非标准模式

2.5 作为值的标签

2.6 long long 数据类型

2.6.1 输出 long long 数据类型

2.6.2 常见算术转换

2.7 switch 语句中的 case 范围

2.8 断言

2.9 支持的属性

2.10 警告和错误

2.11 Pragma

2.11.1 align

2.11.2 c99

2.11.3 does_not_read_global_data

2.11.4 does_not_return

2.11.5 does_not_write_global_data

2.11.6 dumpmacros

2.11.7 end_dumpmacros

2.11.8 error_messages

2.11.9 fini

2.11.10 hdrstop

2.11.11 ident

2.11.12 init

2.11.13 inline

2.11.14 int_to_unsigned

2.11.15 must_have_frame

2.11.16 nomemorydepend

2.11.17 no_side_effect

2.11.18 opt

2.11.19 pack

2.11.20 pipeloop

2.11.21 rarely_called

2.11.22 redefine_extname

2.11.23 returns_new_memory

2.11.24 unknown_control_flow

2.11.25 unroll

2.11.26 warn_missing_parameter_info

2.11.27 weak

2.12 预定义的名称

2.13 保留 errno 的值

2.14 扩展

2.14.1 _Restrict 关键字

2.14.2 _ _asm 关键字

2.14.3 __inline__inline__

2.14.4 __builtin_constant_p()

2.14.5 __FUNCTION____PRETTY_FUNCTION__

2.15 环境变量

2.15.1 PARALLEL

2.15.2 SUN_PROFDATA

2.15.3 SUN_PROFDATA_DIR

2.15.4 TMPDIR

2.16 如何指定 include 文件

2.16.1 使用 -I- 选项更改搜索算法

2.16.1.1 警告

2.17 在独立式环境中编译

2.18 对 Intel MMX 和扩展的 x86 平台内部函数的编译器支持

3.  并行化 C 代码

4.  lint 源代码检验器

5.  基于类型的别名分析

6.  转换为 ISO C

7.  转换应用程序以适用于 64 位环境

8.  cscope:交互检查 C 程序

A.  按功能分组的编译器选项

B.  C 编译器选项参考

C.  实现定义的 ISO/IEC C99 行为

D.  C99 的功能

E.  实现定义的 ISO/IEC C90 行为

F.  ISO C 数据表示法

G.  性能调节

H.  Oracle Solaris Studio C:K&R C 与 ISO C 之间的差异

索引

2.5 作为值的标签

C 编译器可识别称为计算转移 (computed goto) 语句的 C 扩展。使用计算转移 (computed goto) 语句能够在运行时确定分支目标。通过使用 '&&' 运算符可以获取标签的地址,并且可以将标签地址指定给 void * 类型的指针:

void *ptr;
...
ptr = &&label1;

后面的 goto 语句可以通过 ptr 转到 label1

goto *ptr;

由于 ptr 在运行时进行计算,因此 ptr 可以接受作用域内任何标签的地址,而 goto 语句可以转到该位置。

使用计算转移 (computed goto) 语句的一种方法是用于转移表的实现:

static void *ptrarray[] = { &&label1, &&label2, &&label3 };

现在可以通过索引来选择数组元素:

goto *ptrarray[i];

标签的地址只能通过当前函数作用域计算。尝试在当前函数外部获取标签的地址会产生不可预测的结果。

转移表和开关语句的作用相似,但转移表使跟踪程序流更加困难。明显的差别是,开关语句转移目标都在 switch 保留字的正向。使用计算转移 (computed goto) 实现转移表可在正向和反向启用分支。

#include <stdio.h>
void foo()
{
  void *ptr;

  ptr = &&label1;

  goto *ptr;

  printf("Failed!\n");
  return;

  label1:
  printf("Passed!\n");
  return;
}

int main(void)
{
  void *ptr;

  ptr = &&label1;

  goto *ptr;

  printf("Failed!\n");
  return 0;

  label1:
  foo();
  return 0;
}

以下示例也使用转移表控制程序流:

#include <stdio.h>

int main(void)
{
  int i = 0;
  static void * ptr[3]={&&label1, &&label2, &&label3};

  goto *ptr[i];

  label1:
  printf("label1\n");
  return 0;

  label2:
  printf("label2\n");
  return 0;

  label3:
  printf("label3\n");
  return 0;
}

%example: a.out
%example: label1

计算转移 (computed goto) 语句的另一个应用是作为线程代码的解释程序。解释程序函数内部的标签地址可以存储在线程代码中以便快速分发。