JavaScript is required to for searching.
Skip Navigation Links
Exit Print View
Oracle Solaris Studio 12.3: C User's Guide     Oracle Solaris Studio 12.3 Information Library
search filter icon
search icon

Document Information


1.  Introduction to the C Compiler

2.  C-Compiler Implementation-Specific Information

2.1 Constants

2.1.1 Integral Constants

2.1.2 Character Constants

2.2 Linker Scoping Specifiers

2.3 Thread Local Storage Specifier

2.4 Floating Point, Nonstandard Mode

2.5 Labels as Values

2.6 long long Data Type

2.6.1 Printing long long Data Types

2.6.2 Usual Arithmetic Conversions

2.7 Case Ranges in Switch Statements

2.8 Assertions

2.9 Supported Attributes

2.10 Warnings and Errors

2.11 Pragmas

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 Predefined Names

2.13 Preserving the Value of errno

2.14 Extensions

2.14.1 _Restrict Keyword

2.14.2 __asm Keyword

2.14.3 __inline and __inline__

2.14.4 __builtin_constant_p()


2.15 Environment Variables




2.15.4 TMPDIR

2.16 How to Specify Include Files

2.16.1 Using the -I- Option to Change the Search Algorithm Warnings

2.17 Compiling in Free-Standing Environments

2.18 Compiler Support for Intel MMX and Extended x86 Platform Intrinsics

3.  Parallelizing C Code

4.  lint Source Code Checker

5.  Type-Based Alias Analysis

6.  Transitioning to ISO C

7.  Converting Applications for a 64-Bit Environment

8.  cscope: Interactively Examining a C Program

A.  Compiler Options Grouped by Functionality

B.  C Compiler Options Reference

C.  Implementation-Defined ISO/IEC C99 Behavior

D.  Features of C99

E.  Implementation-Defined ISO/IEC C90 Behavior

F.  ISO C Data Representations

G.  Performance Tuning

H.  Oracle Solaris Studio C: Differences Between K&R C and ISO C


2.5 Labels as Values

The C compiler recognizes the extension to C known as computed goto. Computed goto enables runtime determination of branching destinations. The address of a label can be acquired by using the ’&&’ operator and assigned to a pointer of type void *:

void *ptr;
ptr = &&label1;

A later goto statement can branch to label1 through ptr:

goto *ptr;

Because ptr is computed at runtime, ptr can take on the address of any label that is in-scope and the goto statement can branch to it.

One way of using computed goto is for the implementation of a jump table:

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

Now the array elements can be selected by indexing:

goto *ptrarray[i];

Addresses of labels can be computed only from the current function scope. Attempting to take addresses of labels out of the current function yields unpredictable results.

The jump table works similarly to a switch statement although the jump table can make it more difficult to follow program flow. A notable difference is that the switch-statement jump-destinations are all in the forward direction from the switch reserved word. Using computed goto to implement a jump table enables branching in both forward and reverse directions.

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

  ptr = &&label1;

  goto *ptr;



int main(void)
  void *ptr;

  ptr = &&label1;

  goto *ptr;

  return 0;

  return 0;

The following example also makes use of a jump table to control program flow:

#include <stdio.h>

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

  goto *ptr[i];

  return 0;

  return 0;

  return 0;

%example: a.out
%example: label1

Another application of computed goto is as an interpreter for threaded code. The label addresses within the interpreter function can be stored in the threaded code for fast dispatching.