Monado OpenXR Runtime
Loading...
Searching...
No Matches
oxr_handle_cast.h
Go to the documentation of this file.
1// Copyright 2018-2024, Collabora, Ltd.
2// Copyright 2026, NVIDIA CORPORATION.
3// SPDX-License-Identifier: BSL-1.0
4/*!
5 * @file
6 * @brief Macros for casting between OpenXR handles and internal pointers.
7 * @author Jakob Bornecrantz <jakob@collabora.com>
8 * @ingroup oxr
9 */
10
11#pragma once
12
13#include <stdint.h>
14
15
16/*!
17 * @brief Cast a pointer to an OpenXR handle in such a way as to avoid warnings.
18 *
19 * Avoids -Wpointer-to-int-cast by first casting to the same size int, then
20 * promoting to the 64-bit int, then casting to the handle type. That's a lot of
21 * no-ops on 64-bit, but a widening conversion on 32-bit.
22 *
23 * @ingroup oxr
24 */
25#define XRT_CAST_PTR_TO_OXR_HANDLE(HANDLE_TYPE, PTR) ((HANDLE_TYPE)(uint64_t)(uintptr_t)(PTR))
26
27/*!
28 * @brief Cast an OpenXR handle to a pointer in such a way as to avoid warnings.
29 *
30 * Avoids -Wint-to-pointer-cast by first casting to a 64-bit int, then to a
31 * pointer-sized int, then to the desired pointer type. That's a lot of no-ops
32 * on 64-bit, but a narrowing (!) conversion on 32-bit.
33 *
34 * @ingroup oxr
35 */
36#define XRT_CAST_OXR_HANDLE_TO_PTR(PTR_TYPE, HANDLE) ((PTR_TYPE)(uintptr_t)(uint64_t)(HANDLE))