remove ARRAY_SIZE2 since bootloader is only built with C
This commit is contained in:
parent
69a1b555e4
commit
3fec038ed8
@ -89,10 +89,10 @@ static struct TextFile const info[] = {
|
|||||||
// WARNING -- code presumes each non-UF2 file content fits in single sector
|
// WARNING -- code presumes each non-UF2 file content fits in single sector
|
||||||
// Cannot programmatically statically assert .content length
|
// Cannot programmatically statically assert .content length
|
||||||
// for each element above.
|
// for each element above.
|
||||||
STATIC_ASSERT(ARRAY_SIZE2(indexFile) < 512);
|
STATIC_ASSERT(ARRAY_SIZE(indexFile) < 512);
|
||||||
|
|
||||||
|
|
||||||
#define NUM_FILES (ARRAY_SIZE2(info))
|
#define NUM_FILES (ARRAY_SIZE(info))
|
||||||
#define NUM_DIRENTRIES (NUM_FILES + 1) // Code adds volume label as first root directory entry
|
#define NUM_DIRENTRIES (NUM_FILES + 1) // Code adds volume label as first root directory entry
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,149 +26,6 @@ SOFTWARE.
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef ARRAYSIZE2_H
|
|
||||||
#define ARRAYSIZE2_H
|
|
||||||
|
|
||||||
#ifndef __has_feature
|
|
||||||
#define __has_feature(x) 0 // Compatibility with non-clang compilers.
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if __cplusplus >= 199711L
|
|
||||||
#pragma message "using Ivan J. Johnson's ARRAY_SIZE2"
|
|
||||||
|
|
||||||
// Works on older compilers, even Visual C++ 6....
|
|
||||||
// Created by Ivan J. Johnson, March 06, 2007
|
|
||||||
// See http://drdobbs.com/cpp/197800525?pgno=1
|
|
||||||
//
|
|
||||||
// Pseudocode:
|
|
||||||
// if x is not an array
|
|
||||||
// issue a compile-time error
|
|
||||||
// else
|
|
||||||
// use the traditional (non-typesafe) C99 COUNTOF expression
|
|
||||||
//
|
|
||||||
// If the argument is any of:
|
|
||||||
// object of class type, such as an std::vector
|
|
||||||
// floating-point type
|
|
||||||
// function pointer
|
|
||||||
// pointer-to-member
|
|
||||||
// then the first reinterpret_cast<> is not legal (compiler error)
|
|
||||||
//
|
|
||||||
// The type for check1 is chosen and named to help understand
|
|
||||||
// the cause of the error, because the class name is likely to
|
|
||||||
// appear in the compiler error message.
|
|
||||||
//
|
|
||||||
// If check1 succeeds, then the argument must be one of:
|
|
||||||
// an integral type
|
|
||||||
// an enumerated type
|
|
||||||
// a pointer to an object
|
|
||||||
// an array
|
|
||||||
//
|
|
||||||
// Check2 expands approximately to sizeof(check_type(x, &x)),
|
|
||||||
// where check_type is an overloaded function.
|
|
||||||
// Because this is purely a compile-time computation,
|
|
||||||
// the function is never really called or even implemented,
|
|
||||||
// but it lets the compiler apply overload resolution,
|
|
||||||
// which allows further type discrimination.
|
|
||||||
// There are three possibilities to consider:
|
|
||||||
// x is an integral type or enumerated type.
|
|
||||||
// In this case, neither of the two function overloads
|
|
||||||
// is a match, resulting in a compiler error.
|
|
||||||
// x is a pointer to an object.
|
|
||||||
// In this case, the first argument to check_type()
|
|
||||||
// is a pointer and the second one is a pointer-to-pointer.
|
|
||||||
// The best function match is the first overload of check_type,
|
|
||||||
// the one that returns an incomplete type (Is_pointer).
|
|
||||||
// However, because Is_pointer is an incomplete type,
|
|
||||||
// sizeof(Is_pointer) is not a valid expression,
|
|
||||||
// resulting in a compiler error.
|
|
||||||
// x is an array.
|
|
||||||
// In this case, the first argument to check_type()
|
|
||||||
// is an array and the second is a pointer-to-array.
|
|
||||||
// A pointer-to-array is *NOT* convertible to a
|
|
||||||
// pointer-to-pointer, so the first overload of
|
|
||||||
// check_type() is not a match.
|
|
||||||
// However, an array IS convertible to a pointer,
|
|
||||||
// and a pointer-to-array already is a pointer.
|
|
||||||
// Any pointer is convertible to a void*,
|
|
||||||
// so the second function overload is a match.
|
|
||||||
// That overload returns a complete type (Is_array).
|
|
||||||
// Because it's a complete type,
|
|
||||||
// sizeof(Is_array) is a valid expression.
|
|
||||||
// Thus, the compiler has EXCLUDED every possible type
|
|
||||||
// except arrays via compilation errors before reaching
|
|
||||||
// the third line.
|
|
||||||
// Moreover, check1 and check2 are reduced to the value zero,
|
|
||||||
// while the third line is the old type-unsafe C-style macro,
|
|
||||||
// now made entirely type-safe.
|
|
||||||
//
|
|
||||||
// Additional benefits:
|
|
||||||
// The result is itself constexpr
|
|
||||||
//
|
|
||||||
//
|
|
||||||
#define ARRAY_SIZE2(arr) ( \
|
|
||||||
0 * sizeof(reinterpret_cast<const ::Bad_arg_to_COUNTOF*>(arr)) + /*check1*/ \
|
|
||||||
0 * sizeof(::Bad_arg_to_COUNTOF::check_type((arr), &(arr))) + /*check2*/ \
|
|
||||||
sizeof(arr) / sizeof((arr)[0]) /* eval */ \
|
|
||||||
)
|
|
||||||
|
|
||||||
struct Bad_arg_to_COUNTOF {
|
|
||||||
class Is_pointer; // incomplete
|
|
||||||
class Is_array {};
|
|
||||||
template <typename T>
|
|
||||||
static Is_pointer check_type(const T*, const T* const*);
|
|
||||||
static Is_array check_type(const void*, const void*);
|
|
||||||
};
|
|
||||||
|
|
||||||
#elif __cplusplus >= 201103L || /* any compiler claiming C++11 support */ \
|
|
||||||
_MSC_VER >= 1900 || /* Visual C++ 2015 or higher */ \
|
|
||||||
__has_feature(cxx_constexpr) /* CLang versions supporting constexp */
|
|
||||||
|
|
||||||
#pragma message "C++11 version ARRAY_SIZE2"
|
|
||||||
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
template <typename T, std::size_t N>
|
|
||||||
constexpr std::size_t countof(T const (&)[N]) noexcept
|
|
||||||
{
|
|
||||||
return N;
|
|
||||||
}
|
|
||||||
} // namespace detail
|
|
||||||
#define ARRAY_SIZE2(arr) detail::countof(arr)
|
|
||||||
|
|
||||||
#elif _MSC_VER // Visual C++ fallback
|
|
||||||
|
|
||||||
#pragma message "using Microsoft Visual C++ intrinsic ARRAY_SIZE2"
|
|
||||||
#define ARRAY_SIZE2(arr) _countof(arr)
|
|
||||||
|
|
||||||
#elif __cplusplus >= 199711L && ( /* C++ 98 trick */ \
|
|
||||||
defined(__INTEL_COMPILER) || \
|
|
||||||
defined(__clang__) || \
|
|
||||||
(defined(__GNUC__) && ( \
|
|
||||||
(__GNUC__ > 4) || \
|
|
||||||
(__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
|
|
||||||
)))
|
|
||||||
|
|
||||||
#pragma message "C++98 version ARRAY_SIZE2"
|
|
||||||
|
|
||||||
template <typename T, std::size_t N>
|
|
||||||
char(&_ArraySizeHelperRequiresArray(T(&)[N]))[N];
|
|
||||||
#define ARRAY_SIZE2(x) sizeof(_ArraySizeHelperRequiresArray(x))
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
#pragma message "Using type-unsafe version of ARRAY_SIZE2"
|
|
||||||
// This is the worst-case scenario macro.
|
|
||||||
// While it is valid C, it is NOT typesafe.
|
|
||||||
// For example, if the parameter arr is a pointer instead of array,
|
|
||||||
// the compiler will SILENTLY give a (likely) incorrect result.
|
|
||||||
#define ARRAY_SIZE2(arr) sizeof(arr) / sizeof(arr[0])
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#endif // ARRAYSIZE2_H
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef COMPILE_DATE_H
|
#ifndef COMPILE_DATE_H
|
||||||
#define COMPILE_DATE_H
|
#define COMPILE_DATE_H
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user