C/C++ API Reference
Loading...
Searching...
No Matches
linker_symbol.h
1// Copyright 2024 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14#pragma once
15
16#include <cstdint>
17#include <type_traits>
18
19#include "lib/stdcompat/bit.h"
20
21namespace pw {
22
24
53template <class T = uintptr_t>
55 public:
56 LinkerSymbol() = delete;
57 ~LinkerSymbol() = delete;
58 LinkerSymbol(const LinkerSymbol&) = delete;
59 LinkerSymbol(const LinkerSymbol&&) = delete;
60 LinkerSymbol& operator=(const LinkerSymbol&) = delete;
61 LinkerSymbol& operator=(const LinkerSymbol&&) = delete;
62
64 T value() const {
65 static_assert(std::is_integral_v<T> || std::is_enum_v<T>);
66 static_assert(sizeof(T) <= sizeof(uintptr_t));
67 return static_cast<T>(raw_value());
68 }
69
70 private:
72 uintptr_t raw_value() const { return cpp20::bit_cast<uintptr_t>(this); }
73};
74
75} // namespace pw
Definition: linker_symbol.h:54
T value() const
Gets the value of this linker symbol, converted to the specified type.
Definition: linker_symbol.h:64
The Pigweed namespace.
Definition: alignment.h:27