---
name: "gd_get_constant"
section: "3"
platform: "linux"
package: "libgetdata-doc"
version: "0.11.0-15"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/gd_get_carray_slice"
---

# gd\_get\_constant(3)

retrieve CONST or CARRAY data from a Dirfile database

Part of [gd\_get\_carray\_slice(3)](/gd_get_carray_slice/3.md).

## NAME

gd\_get\_carray, gd\_get\_carray\_slice, gd\_get\_constant — retrieve CONST or CARRAY data from a Dirfile database

## SYNOPSIS

**#include \<getdata.h\>**

**int gd\_get\_carray\_slice(DIRFILE \****dirfile***, const char \****field\_code***,** **unsigned int** *start***, size\_t** *len***, gd\_type\_t** *return\_type***,** **void \****data\_out***);**

**int gd\_get\_carray(DIRFILE \****dirfile***, const char \****field\_code***,** **gd\_type\_t** *return\_type***, void \****data\_out***);**

**int gd\_get\_constant(DIRFILE \****dirfile***, const char \****field\_code***,** **gd\_type\_t** *return\_type***, void \****data\_out***);**

## DESCRIPTION

The **gd\_get\_carray\_slice**() function queries a [dirfile(5)](/dirfile/5.md) database specified by *dirfile* for the **CONST** or **CARRAY** scalar *field\_code*, which may contain a representation suffix. The data in the field is converted to the data type specified by *return\_type*, and stored in the user-supplied buffer *data\_out*. The first element of the field stored is given by *start*, and the number of elements stored is given by *len*.

The **gd\_get\_carray**() function behaves similarly, except it returns the entire field, as if **gd\_get\_carray\_slice**() were called with *start* equal to zero and *len* equal to the value returned by [**gd\_array\_len**(3)](/gd_array_len/3.md). The **gd\_get\_constant**() function is equivalent to calling **gd\_get\_carray\_slice**() with *start* equal to zero and *len* equal to one.

The  *dirfile* argument must point to a valid DIRFILE object previously created by a call to [**gd\_open**(3)](/gd_open/3.md). The argument *data\_out* must point to a valid memory location of sufficient size to hold all the requested data of the return type specified.  The number of elements returned by **gd\_get\_carray**() may be obtained by calling [**gd\_array\_len**(3)](/gd_array_len/3.md). Unlike [**gd\_getdata**(3)](/gd_getdata/3.md), calling **gd\_get\_carray\_slice**() never results in a short read; attempting to read past the end of the field will result in an error, and no data will be returned.

The  *return\_type* argument should be one of the following symbols, which indicates the desired return type of the data:

 .TP 8 **GD\_UINT8** unsigned 8-bit integer\
  .TP 8 **GD\_INT8** signed (two's complement) 8-bit integer\
  .TP 8 **GD\_UINT16** unsigned 16-bit integer\
  .TP 8 **GD\_INT16** signed (two's complement) 16-bit integer\
  .TP 8 **GD\_UINT32** unsigned 32-bit integer\
  .TP 8 **GD\_INT32** signed (two's complement) 32-bit integer\
  .TP 8 **GD\_UINT64** unsigned 64-bit integer\
  .TP 8 **GD\_INT64** signed (two's complement) 64-bit integer\
  .TP 8 **GD\_FLOAT32** IEEE-754 standard 32-bit single precision floating point number\
  .TP 8 **GD\_FLOAT64** IEEE-754 standard 64-bit double precision floating point number\
  .TP 8 **GD\_COMPLEX64** C99-conformant 64-bit single precision complex number\
  .TP 8 **GD\_COMPLEX128** C99-conformant 128-bit double precision complex number\
  .TP 8 **GD\_NULL** the null type: the database is queried as usual, but no data is returned. In this case, *data\_out* is ignored and may be NULL.

The return type of the field need not be the same as the type of the data stored in the database.  Type conversion will be performed as necessary to return the requested type.  If the *field\_code* does not indicate a representation, but conversion from a complex value to a purely real one is required, only the real portion of the requested vector will be returned.

## RETURN VALUE

On success, **gd\_get\_carray**(), **gd\_get\_carray\_slice**(), and **gd\_get\_constant**() return zero.  On error, they return a negative-valued error code.  Possible error codes are:\
  .TP 8 **GD\_E\_ALLOC** The library was unable to allocate memory.\
  .TP 8 **GD\_E\_BAD\_CODE** The field specified by *field\_code* was not found in the database.\
  .TP 8 **GD\_E\_BAD\_DIRFILE** An invalid *dirfile* was supplied.\
  .TP 8 **GD\_E\_BAD\_FIELD\_TYPE** The supplied *field\_code* was not a **CONST** nor **CARRAY**.\
  .TP 8 **GD\_E\_BAD\_TYPE** An invalid *return\_type* was specified.\
  .TP 8 **GD\_E\_BOUNDS** A request for data beyond the end of the field was made.\
  .TP 8 **GD\_E\_INTERNAL\_ERROR** An internal error occurred in the library while trying to perform the task. This indicates a bug in the library.  Please report the incident to the maintainer.

The error code is also stored in the **DIRFILE** object and may be retrieved after this function returns by calling [**gd\_error**(3)](/gd_error/3.md). A descriptive error string for the error may be obtained by calling [**gd\_error\_string**(3)](/gd_error_string/3.md).

## HISTORY

The **get\_constant**() function appeared in GetData-0.4.0.

In GetData-0.7.0, this function was renamed to **gd\_get\_constant**(). In this release, the **gd\_get\_carray**() and **gd\_get\_carray\_slice**() functions also appeared.

In GetData-0.10.0, the error return from these functions changed from -1 to a negative-valued error code.

## SEE ALSO

[**gd\_array\_len**(3)](/gd_array_len/3.md), [**gd\_carrays**(3)](/gd_carrays/3.md), [**gd\_error**(3)](/gd_error/3.md), [**gd\_error\_string**(3)](/gd_error_string/3.md), [**gd\_open**(3)](/gd_open/3.md), [**gd\_put\_carray\_slice**(3)](/gd_put_carray_slice/3.md), [dirfile(5)](/dirfile/5.md)
