Skip to content

Commit

Permalink
fix: Fix compile error with g++
Browse files Browse the repository at this point in the history
  • Loading branch information
TheWaWaR committed Nov 6, 2020
1 parent 7cb529a commit 8510157
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
18 changes: 8 additions & 10 deletions molecule/molecule_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
#define MOLECULE_BUILDER_H

#ifdef __cplusplus
#define _CPP_BEGIN extern "C" {
#define _CPP_END }
_CPP_BEGIN
extern "C" {
#endif /* __cplusplus */

#include <stddef.h>
Expand All @@ -17,9 +15,6 @@ _CPP_BEGIN
* This part is not for normal users.
*/

// Test if the host is big endian machine.
#define is_le() (*(unsigned char *)&(uint16_t){1})

/*
* Definitions of types and simple utilities.
*/
Expand All @@ -45,8 +40,13 @@ typedef struct {
/* Utilities. */

void mol_pack_number(uint8_t *dst, mol_num_t *num) {
const static union {
uint16_t i;
char c[2];
} bint = {0x0102};

const uint8_t *src = (const uint8_t *)num;
if (is_le()) {
if (bint.c[0] != 1) {
memcpy(dst, src, MOL_NUM_T_SIZE);
} else {
dst[3] = src[0];
Expand Down Expand Up @@ -308,9 +308,7 @@ mol_seg_res_t mol_dynvec_builder_finalize(mol_builder_t builder) {
#undef is_le

#ifdef __cplusplus
_CPP_END
#undef _CPP_BEGIN
#undef _CPP_END
}
#endif /* __cplusplus */

#endif /* MOLECULE_BUILDER_H */
20 changes: 8 additions & 12 deletions molecule/molecule_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
#define MOLECULE_READER_H

#ifdef __cplusplus
#define _CPP_BEGIN extern "C" {
#define _CPP_END }
_CPP_BEGIN
extern "C" {
#endif /* __cplusplus */

#include <stdbool.h>
Expand All @@ -14,9 +12,6 @@ _CPP_BEGIN
* This part is not for normal users.
*/

// Test if the host is big endian machine.
#define is_le() (*(unsigned char *)&(uint16_t){1})

/*
* Definitions of types and simple utilities.
*/
Expand Down Expand Up @@ -65,7 +60,12 @@ typedef struct {
/* Utilities. */

mol_num_t mol_unpack_number(const uint8_t *src) {
if (is_le()) {
const static union {
uint16_t i;
char c[2];
} bint = {0x0102};

if (bint.c[0] != 1) {
return *(const uint32_t *)src;
} else {
uint32_t output = 0;
Expand Down Expand Up @@ -223,12 +223,8 @@ mol_seg_t mol_fixvec_slice_raw_bytes(const mol_seg_t *input) {
* Undef macros which are internal use only.
*/

#undef is_le

#ifdef __cplusplus
_CPP_END
#undef _CPP_BEGIN
#undef _CPP_END
}
#endif /* __cplusplus */

#endif /* MOLECULE_READER_H */

0 comments on commit 8510157

Please sign in to comment.