JavaScript is required to for searching.
Skip Navigation Links
Exit Print View
Solaris 64-bit Developer's Guide
search filter icon
search icon

Document Information

Preface

1.  64-bit Computing

2.  When to Use 64-bit

3.  Comparing 32-bit Interfaces and 64-bit Interfaces

4.  Converting Applications

Data Model

Implementing Single-Source Code

Feature Test Macros

Derived Types

<sys/types.h> File

<inttypes.h> File

Fixed-Width Integer Types

uintptr_t and Other Helpful Types

Constant Macros

Limits Defined by <inttypes.h>

Format String Macros

Tools Support

lint for 32-bit and 64-bit Environments

Guidelines for Converting to LP64

Do Not Assume int and Pointers Are the Same Size

Do Not Assume int and long Are the Same Size

Sign Extension

Use Pointer Arithmetic Instead of Address Arithmetic

Repacking a Structure

Check Unions

Specify Constant Types

Beware of Implicit Declaration

sizeof is an unsigned long

Use Casts to Show Your Intentions

Check Format String Conversion Operation

Other Considerations

Derived Types That Have Grown in Size

Check for Side Effects of Changes

Check Whether Literal Uses of long Still Make Sense

Use #ifdef for Explicit 32-bit Versus 64-bit Prototypes

Algorithmic Changes

Checklist for Getting Started

Sample Program

5.  The Development Environment

6.  Advanced Topics

A.  Changes in Derived Types

B.  Frequently Asked Questions (FAQs)

Index

Tools Support

The lint program, available with the Sun Studio 10 compiler, can detect potential 64-bit problems and is useful in making code 64-bit safe. In addition, the -v option to the C compiler can be very helpful. It tells the compiler to perform additional and stricter semantic checks. It also enables certain lint-like checks on the named files.

For more information about the capabilities of the C compilers and lint, see the Sun Studio 10: C User's Guide.

lint for 32–bit and 64–bit Environments

lint can be used on both 32-bit and 64-bit code. Use the -errchk=longptr64 option for code that is intended to be run in both 32–bit and 64–bit environments. The -errchk=longptr64 option checks portability to an environment in which the size of long integers and pointers is 64 bits and the size of plain integers is 32 bits.

The -Xarch=v9 option should be used to lint code intended to be run in the 64–bit SPARC environment. Use the -errchk=longptr64 option together with the -Xarch=v9 option to generate warnings about potential 64–bit problems for code to be run on 64–bit SPARC.

Starting with the Solaris 10 release, the -Xarch=amd64 option should be used to lint code intended to be run in the 64–bit AMD environment.


Note - The -D__sparcv9 option to lint is no longer necessary and should not be used.


For a description of lint options, see the Sun Studio 10: C User's Guide.

When warnings are generated, lint(1) prints the line number of the offending code, a warning message that describes the problem, and notes whether a pointer was involved. It can also indicate the sizes of types involved. The fact that a pointer is involved and the size of the types can be useful in finding specific 64-bit problems and avoiding the pre-existing problems between 32-bit and smaller types.


Note - Though lint gives warnings about potential 64-bit problems, it cannot detect all problems. You must remember that not all warnings generated by lint are true 64-bit problems. In many cases, code that generates a warning can be intentional and correct for the application.


The sample program and lint(1) output below illustrate most of the lint warnings that can arise in code that is not 64–bit clean.

    1    #include <inttypes.h>
    2    #include <stdio.h>
    3    #include <stdlib.h>
    4    
    5    static char chararray[] = "abcdefghijklmnopqrstuvwxyz";
    6    
    7    static char *myfunc(int i)
    8    {    
    9        return(& chararray[i]);
   10    }
   11    
   12    void main(void)
   13    {
   14        int    intx;
   15        long    longx;
   16        char    *ptrx;
   17    
   18        (void) scanf("%d", &longx);
   19        intx = longx;
   20        ptrx = myfunc(longx);
   21        (void) printf("%d\n", longx);
   22        intx = ptrx;
   23        ptrx = intx;
   24        intx = (int)longx;
   25        ptrx = (char *)intx;
   26        intx = 2147483648L;
   27        intx = (int) 2147483648L;
   28        ptrx = myfunc(2147483648L);
   29    }

(19) warning: assignment of 64-bit integer to 32-bit integer
(20) warning: passing 64-bit integer arg, expecting 32-bit integer: myfunc(arg 1)
(22) warning: improper pointer/integer combination: op "="
(22) warning: conversion of pointer loses bits
(23) warning: improper pointer/integer combination: op "="
(23) warning: cast to pointer from 32-bit integer
(24) warning: cast from 64-bit integer to 32-bit integer
(25) warning: cast to pointer from 32-bit integer
(26) warning: 64-bit constant truncated to 32 bits by assignment
(27) warning: cast from 64-bit integer constant expression to 32-bit integer
(28) warning: passing 64-bit integer constant arg, expecting 32-bit integer: myfunc(arg 1)
function argument ( number ) type inconsistent with format
    scanf (arg 2)     long * :: (format) int *    t.c(18)
    printf (arg 2)     long  :: (format) int     t.c(21)

(The lint warning that arises from line 27 of this code sample is issued only if the constant expression will not fit into the type into which it is being cast.)

Warnings for a given source line can be suppressed by placing a /*LINTED*/ comment on the previous line. This is useful where you have really intended the code to be a specific way. An example might be in the case of casts and assignments. Exercise extreme care when using the /*LINTED*/ comment because it can mask real problems. Refer to the Sun Studio 10: C User's Guide or the lint(1) man page for more information.