Skip to content

Commit ec20fa5

Browse files
committed
moved the byte order function to an implementation file - the constexpr approach does not work on all compliers -- needs > c++11
1 parent c1e9004 commit ec20fa5

File tree

2 files changed

+45
-6
lines changed

2 files changed

+45
-6
lines changed

src/sfeTk/sfeToolkit.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// File: sfeToolkit.cpp
2+
//
3+
// General impl file for the SparkFun Toolkit
4+
/*
5+
6+
The MIT License (MIT)
7+
8+
Copyright (c) 2024 SparkFun Electronics
9+
10+
Permission is hereby granted, free of charge, to any person obtaining a
11+
copy of this software and associated documentation files (the "Software"),
12+
to deal in the Software without restriction, including without limitation
13+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
14+
and/or sell copies of the Software, and to permit persons to whom the
15+
Software is furnished to do so, subject to the following conditions: The
16+
above copyright notice and this permission notice shall be included in all
17+
copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED
18+
"AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
19+
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
20+
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22+
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24+
*/
25+
#include "sfeToolkit.h"
26+
#include <stdint.h>
27+
28+
/**
29+
* @brief C function - Runtime check for system byte order
30+
*/
31+
sfeTKByteOrder_t systemByteOrder(void)
32+
{
33+
uint16_t i = 1;
34+
return *((uint8_t *)&i) == 0 ? SFETK_BIG_ENDIAN : SFETK_LITTLE_ENDIAN;
35+
}

src/sfeTk/sfeToolkit.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
The MIT License (MIT)
88
9-
Copyright (c) 2023 SparkFun Electronics
9+
Copyright (c) 2024 SparkFun Electronics
1010
1111
Permission is hereby granted, free of charge, to any person obtaining a
1212
copy of this software and associated documentation files (the "Software"),
@@ -40,9 +40,13 @@ typedef enum
4040
SFETK_LITTLE_ENDIAN = 0x00
4141
} sfeTKByteOrder_t;
4242

43-
// Runtime check for system byte order
44-
constexpr sfeTKByteOrder_t systemByteOrder(void)
43+
// Export our byte order function as a C function
44+
#ifdef __cplusplus
45+
extern "C"
4546
{
46-
uint16_t i = 1;
47-
return *((uint8_t *)&i) == 0 ? SFETK_BIG_ENDIAN : SFETK_LITTLE_ENDIAN;
48-
}
47+
#endif
48+
// Runtime check for system byte order
49+
sfeTKByteOrder_t systemByteOrder(void);
50+
#ifdef __cplusplus
51+
}
52+
#endif

0 commit comments

Comments
 (0)