Skip to content

Commit 8f8dd49

Browse files
brvtalcakeridiculousfish
authored andcommitted
Update libdivide.h to support -ffreestanding targets
Simply check for the value of the `__STDC_HOSTED__` macro before including `<stdlib.h>` or `<stdio.h>` and others. Moreover, as an idea for future changes, you could also add some checks for user-provided `LIBDIVIDE_{ERROR|ASSERT}`, as printing to the screen and aborting the program is not always a good thing to do anyways (and is sometimes not even possible, in the case of a freestanding environment)
1 parent 99fad03 commit 8f8dd49

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

libdivide.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#include <stdint.h>
2121

22-
#if !defined(__AVR__)
22+
#if !defined(__AVR__) && __STDC_HOSTED__ != 0
2323
#include <stdio.h>
2424
#include <stdlib.h>
2525
#endif
@@ -109,7 +109,7 @@
109109
#endif
110110
#endif
111111

112-
#if defined(__AVR__)
112+
#if defined(__AVR__) || __STDC_HOSTED__ == 0
113113
#define LIBDIVIDE_ERROR(msg)
114114
#else
115115
#define LIBDIVIDE_ERROR(msg) \
@@ -119,7 +119,7 @@
119119
} while (0)
120120
#endif
121121

122-
#if defined(LIBDIVIDE_ASSERTIONS_ON) && !defined(__AVR__)
122+
#if defined(LIBDIVIDE_ASSERTIONS_ON) && !defined(__AVR__) && __STDC_HOSTED__ != 0
123123
#define LIBDIVIDE_ASSERT(x) \
124124
do { \
125125
if (!(x)) { \

0 commit comments

Comments
 (0)