Minh Nguyen / ArduinoJson
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers alias_cast.hpp Source File

alias_cast.hpp

00001 // ArduinoJson - arduinojson.org
00002 // Copyright Benoit Blanchon 2014-2021
00003 // MIT License
00004 
00005 #pragma once
00006 
00007 #include <stdint.h>
00008 #include <stdlib.h>  // for size_t
00009 
00010 #include <ArduinoJson/Configuration.hpp>
00011 #include "math.hpp"
00012 
00013 namespace ARDUINOJSON_NAMESPACE {
00014 
00015 template <typename T, typename F>
00016 struct alias_cast_t {
00017   union {
00018     F raw;
00019     T data;
00020   };
00021 };
00022 
00023 template <typename T, typename F>
00024 T alias_cast(F raw_data) {
00025   alias_cast_t<T, F> ac;
00026   ac.raw = raw_data;
00027   return ac.data;
00028 }
00029 }  // namespace ARDUINOJSON_NAMESPACE