---
name: "constant"
section: "3clc"
platform: "linux"
package: "opencl-1.2-man-doc"
version: "1.0~svn33624-5.1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/constant"
---

# constant(3clc)

Address Space Qualifier.

## NAME

\_\_constant - Address Space Qualifier.

###

| |
| --- |
| \_\_constant constant |

## DESCRIPTION

OpenCL implements the following disjoint address spaces: **\_\_global**, **\_\_local**, **\_\_constant**, and **\_\_private** The address space qualifier may be used in variable declarations to specify the region of memory that is used to allocate the object. The C syntax for type qualifiers is extended in OpenCL to include an address space name as a valid type qualifier. If the type of an object is qualified by an address space name, the object is allocated in the specified address name; otherwise, the object is allocated in the generic address space.

The address space names without the \_\_prefix i.e. **global**, **local**, **constant** and **private** may be substituted for the corresponding address space names with the \_\_prefix.

The generic address space name for arguments to a function in a program, or local variables of a function is **\_\_private**. All function arguments shall be in the **\_\_private** address space.

[**functionQualifiers**(3clc)](/functionQualifiers/3clc.md) function arguments declared to be a pointer of a type can point to one of the following address spaces only: **\_\_global**, **\_\_local** or **\_\_constant**. A pointer to address space A can only be assigned to a pointer to the same address space A. Casting a pointer to address space A to a pointer to address space B is illegal.

Function arguments of type [**otherDataTypes**(3clc)](/otherDataTypes/3clc.md), [**otherDataTypes**(3clc)](/otherDataTypes/3clc.md), [**otherDataTypes**(3clc)](/otherDataTypes/3clc.md), [**otherDataTypes**(3clc)](/otherDataTypes/3clc.md), [**otherDataTypes**(3clc)](/otherDataTypes/3clc.md), and [**otherDataTypes**(3clc)](/otherDataTypes/3clc.md) refer to image memory objects allocated in the **\_\_global** address space.

## NOTES

The **\_\_constant** or **constant** address space name is used to describe variables allocated in global memory and which are accessed inside a kernel(s) as read-only variables. These readonly variables can be accessed by all (global) work-items of the kernel during its execution. Pointers to the **\_\_constant** address space are allowed as arguments to functions (including kernel functions) and for variables declared inside functions.

All string literal storage shall be in the **\_\_constant** address space.

NOTE: Each argument to a kernel that is a pointer to the **\_\_constant** address space is counted separately towards the maximum number of such arguments, defined as **CL\_DEVICE\_MAX\_CONSTANT\_ARGS** are described in the table for [**clGetDeviceInfo**(3clc)](/clGetDeviceInfo/3clc.md).

Variables in the program scope or the outermost scope of kernel functions can be declared in the **\_\_constant** address space. These variables are required to be initialized and the values used to initialize these variables must be a compile time constant. Writing to such a variable results in a compile-time error.

Implementations are not required to aggregate these declarations into the fewest number of constant arguments. This behavior is implementation defined.

Thus portable code must conservatively assume that each variable declared inside a function or in program scope allocated in the **\_\_constant** address space counts as a separate constant argument.

### Example

There is no generic address space name for program scope variables. All program scope variables must be declared in the **\_\_constant** address space. For example:

| |
| --- |
| // declares a pointer p in the \_\_private address space that // points to an int object in address space \_\_global \_\_global int \*p; // declares an array of 4 floats in the \_\_private address space. float x\[4\]; |

There is no address space for function return values. Using an address space qualifier in a function return type declaration will generate a compilation error, unless the return type is declared as a pointer type and the qualifier is used on the points-to address space.

For example:

| |
| --- |
| \_\_private int f() { ... } // should generate an error \_\_local int \*f() { ... } // allowed \_\_local int \* \_\_private f() { ... }; // should generate an error. |

## SPECIFICATION

**OpenCL Specification**\[1\]

## SEE ALSO

[**global**(3clc)](/global/3clc.md), [**local**(3clc)](/local/3clc.md), [**private**(3clc)](/private/3clc.md)

## AUTHORS

**The Khronos Group**

## COPYRIGHT

Copyright © 2007-2011 The Khronos Group Inc.\
 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and/or associated documentation files (the "Materials"), to deal in the Materials without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Materials, and to permit persons to whom the Materials are furnished to do so, subject to the condition that this copyright notice and permission notice shall be included in all copies or substantial portions of the Materials.

## NOTES

- 1\.

  OpenCL Specification

  page 222, section 6.5 - Address Space Qualifiers
