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

Document Information

Preface

1.  Introduction to the C Compiler

2.  C-Compiler Implementation-Specific Information

3.  Parallelizing C Code

4.  lint Source Code Checker

5.  Type-Based Alias Analysis

5.1 Introduction to Type-Based Analysis

5.2 Using Pragmas for Finer Control

5.2.1 #pragma alias_level level (list)

5.2.1.1 #pragma alias (type, type [, type]...)

5.2.1.2 #pragma alias (pointer, pointer [, pointer]...)

5.2.1.3 #pragma may_point_to (pointer, variable [, variable]...)

5.2.1.4 #pragma noalias (type, type [, type]...)

5.2.1.5 #pragma noalias (pointer, pointer [, pointer]...)

5.2.1.6 #pragma may_not_point_to (pointer, variable [, variable]...)

5.3 Checking With lint

5.3.1 Struct Pointer Cast of Scalar Pointer

5.3.2 Struct Pointer Cast of Void Pointer

5.3.3 Cast of Struct Field to Structure Pointer

5.3.4 Explicit Aliasing Required

5.4 Examples of Memory Reference Constraints

5.4.1 First Example

5.4.2 Second Example

5.4.3 Third Example

5.4.4 Fourth Example

5.4.5 Fifth Example

5.4.6 Sixth Example

5.4.7 Seventh Example

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.  Supported Features of C99

E.  Implementation-Defined ISO/IEC C90 Behavior

F.  ISO C Data Representations

G.  Performance Tuning

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

Index

5.3 Checking With lint

The lint program recognizes the same levels of type-based alias-disambiguation as the compiler’s -xalias_level command. The lint program also recognizes the pragmas related to type-based alias-disambiguation documented in this chapter. For a detailed explanation of the lint -Xalias_level command, see 4.3.38 -Xalias_level[=l].

There are four situations that lint detects and for which it generates warnings:

5.3.1 Struct Pointer Cast of Scalar Pointer

In the following example, the pointer p of type integer is cast as a pointer of type struct foo. With lint -Xalias_level=weak (or higher), this generates an error.

struct foo {
    int a;
    int b;
  };

struct foo *f;
int *p;

void main()
{
    f = (struct foo *)p; /* struct pointer cast of scalar pointer error */
}

5.3.2 Struct Pointer Cast of Void Pointer

In the following example, the void pointer vp, is cast as a struct pointer. With lint -Xalias_level=weak (or higher), this generates a warning.

struct foo {
    int a;
    int b;
  };

struct foo *f;
void *vp;

void main()
{
    f = (struct foo *)vp; /* struct pointer cast of void pointer warning */
}

5.3.3 Cast of Struct Field to Structure Pointer

In the following example, the address of structure member foo.b is being cast as a struct pointer and then assigned to f2. With lint -Xalias_level=weak (or higher), this generates an error.

struct foo{
    int a;
    int b;
  };

struct foo *f1;
struct foo *f2;

void main()
{
    f2 = (struct foo *)&f1->b; /* cast of a scalar pointer to struct pointer error*/
}

5.3.4 Explicit Aliasing Required

In the following example, the pointer f1 of type struct fooa is being cast as a pointer of type struct foob. With lint -Xalias_level=strict (or higher) such a cast requires explicit aliasing, unless the struct types are identical (the same number of fields of the same type). In addition, at alias levels standard and strong, the assumptions is that the tags must match for aliasing to occur. Use #pragma alias (struct fooa, struct foob) before the assignment to f1 and lint stops generating the warning.

struct fooa {
    int a;
};

struct foob {
    int b;
};

struct fooa *f1;
struct foob *f2;

void main()
{
    f1 = (struct fooa *)f2; /* explicit aliasing required warning */
}