Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: UAVCAN UAVCAN_Subscriber
std.hpp
00001 /* 00002 * Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com> 00003 */ 00004 00005 #ifndef UAVCAN_STD_HPP_INCLUDED 00006 #define UAVCAN_STD_HPP_INCLUDED 00007 00008 #include <uavcan/build_config.hpp> 00009 #include <cstdarg> 00010 #include <cstddef> 00011 00012 #if !defined(UAVCAN_CPP_VERSION) || !defined(UAVCAN_CPP11) 00013 # error UAVCAN_CPP_VERSION 00014 #endif 00015 00016 #if UAVCAN_CPP_VERSION >= UAVCAN_CPP11 00017 00018 # include <cstdint> 00019 # include <cstdio> 00020 00021 namespace uavcan 00022 { 00023 00024 typedef std::uint8_t uint8_t; 00025 typedef std::uint16_t uint16_t; 00026 typedef std::uint32_t uint32_t; 00027 typedef std::uint64_t uint64_t; 00028 00029 typedef std::int8_t int8_t; 00030 typedef std::int16_t int16_t; 00031 typedef std::int32_t int32_t; 00032 typedef std::int64_t int64_t; 00033 00034 } 00035 00036 #else 00037 00038 # include <stdint.h> // Standard integer types from C library 00039 # include <stdio.h> // vsnprintf() from the C library 00040 00041 namespace uavcan 00042 { 00043 00044 typedef ::uint8_t uint8_t; 00045 typedef ::uint16_t uint16_t; 00046 typedef ::uint32_t uint32_t; 00047 typedef ::uint64_t uint64_t; 00048 00049 typedef ::int8_t int8_t; 00050 typedef ::int16_t int16_t; 00051 typedef ::int32_t int32_t; 00052 typedef ::int64_t int64_t; 00053 00054 } 00055 00056 #endif 00057 00058 namespace uavcan 00059 { 00060 /** 00061 * Wrapper over the standard snprintf(). This wrapper is needed because different standards and different 00062 * implementations of C++ do not agree whether snprintf() should be defined in std:: or in ::. The solution 00063 * is to use 'using namespace std' hack inside the wrapper, so the compiler will be able to pick whatever 00064 * definition is available in the standard library. Alternatively, the user's application can provide a 00065 * custom implementation of uavcan::snprintf(). 00066 */ 00067 #if __GNUC__ 00068 __attribute__ ((format(printf, 3, 4))) 00069 #endif 00070 extern int snprintf(char* out, std::size_t maxlen, const char* format, ...); 00071 00072 #if !UAVCAN_USE_EXTERNAL_SNPRINTF 00073 inline int snprintf(char* out, std::size_t maxlen, const char* format, ...) 00074 { 00075 using namespace std; // This way we can pull vsnprintf() either from std:: or from ::. 00076 va_list args; 00077 va_start(args, format); 00078 const int return_value = vsnprintf(out, maxlen, format, args); 00079 va_end(args); 00080 return return_value; 00081 } 00082 #endif 00083 00084 } 00085 00086 #endif // UAVCAN_STD_HPP_INCLUDED
Generated on Tue Jul 12 2022 17:17:34 by
1.7.2