summaryrefslogtreecommitdiff
path: root/docs/reference/src/ctx/nng_ctx_id.md
blob: 6592da7d45ee40d36472ba57e564f16fa0b8a691 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# nng_ctx_id

## NAME

nng_ctx_id --- return numeric context identifier

## SYNOPSIS

```c
#include <nng/nng.h>

int nng_ctx_id(nng_ctx c);
```

## DESCRIPTION

The `nng_ctx_id()` function returns a positive identifier for the [context][context] _c_,
if it is valid.
Otherwise it returns `-1`.

> [!NOTE]
> A context is considered valid if it was ever opened with
> [`nng_ctx_open()`][nng_ctx_open] function.
> Contexts that are allocated on the stack or statically should be
> initialized with the macro {{i:`NNG_CTX_INITIALIZER`}} to ensure that
> they cannot be confused with a valid context before they are opened.

## RETURN VALUES

This function returns the positive value for the context identifier, or
`-1` if the context is invalid.

{{#include ../refs.md}}