Skip to content

Commit 59d13db

Browse files
committed
Update C examples
1 parent 779f83b commit 59d13db

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/node_modules/@stdlib/os/byte-order/README.md

+14-2
Original file line numberDiff line numberDiff line change
@@ -111,30 +111,36 @@ if ( BYTE_ORDER === 'little-endian' ) {
111111
Macro for an arbitrary constant indicating little-endian byte order.
112112

113113
```c
114-
#if STDLIB_OS_BYTE_ORDER == STDLIB_OS_BYTE_ORDER_LITTLE_ENDIAN
114+
#if defined(STDLIB_OS_BYTE_ORDER) && STDLIB_OS_BYTE_ORDER == STDLIB_OS_BYTE_ORDER_LITTLE_ENDIAN
115115

116116
// Do something for little-endian...
117117

118118
#endif
119119
```
120120

121+
If compiled on an unrecognized/unsupported platform, the macro is **not** defined.
122+
121123
#### STDLIB_OS_BYTE_ORDER_BIG_ENDIAN
122124

123125
Macro for an arbitrary constant indicating big-endian byte order.
124126

125127
```c
126-
#if STDLIB_OS_BYTE_ORDER == STDLIB_OS_BYTE_ORDER_BIG_ENDIAN
128+
#if defined(STDLIB_OS_BYTE_ORDER) && STDLIB_OS_BYTE_ORDER == STDLIB_OS_BYTE_ORDER_BIG_ENDIAN
127129

128130
// Do something for big-endian...
129131

130132
#endif
131133
```
132134

135+
If compiled on an unrecognized/unsupported platform, the macro is **not** defined.
136+
133137
#### STDLIB_OS_BYTE_ORDER
134138

135139
Macro which equals either `STDLIB_OS_BYTE_ORDER_LITTLE_ENDIAN` or `STDLIB_OS_BYTE_ORDER_BIG_ENDIAN` depending on the resolved platform byte order.
136140

137141
```c
142+
#if defined(STDLIB_OS_BYTE_ORDER)
143+
138144
#if STDLIB_OS_BYTE_ORDER == STDLIB_OS_BYTE_ORDER_LITTLE_ENDIAN
139145

140146
// Do something for little-endian...
@@ -143,9 +149,13 @@ Macro which equals either `STDLIB_OS_BYTE_ORDER_LITTLE_ENDIAN` or `STDLIB_OS_BYT
143149

144150
// Do something for big-endian...
145151

152+
#endif
153+
146154
#endif
147155
```
148156

157+
If compiled on an unrecognized/unsupported platform, the macro is **not** defined.
158+
149159
</section>
150160

151161
<!-- /.usage -->
@@ -169,13 +179,15 @@ Macro which equals either `STDLIB_OS_BYTE_ORDER_LITTLE_ENDIAN` or `STDLIB_OS_BYT
169179
#include <stdio.h>
170180

171181
int main() {
182+
#if defined(STDLIB_OS_BYTE_ORDER)
172183
#if STDLIB_OS_BYTE_ORDER == STDLIB_OS_BYTE_ORDER_LITTLE_ENDIAN
173184
printf( "Platform is little-endian...\n" );
174185
#elif STDLIB_OS_BYTE_ORDER == STDLIB_OS_BYTE_ORDER_BIG_ENDIAN
175186
printf( "Platform is big-endian...\n" );
176187
#else
177188
printf( "Platform endianness is either mixed-endian or unknown...\n" )
178189
#endif
190+
#endif
179191
}
180192
```
181193

lib/node_modules/@stdlib/os/byte-order/examples/c/example.c

+2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@
2020
#include <stdio.h>
2121

2222
int main() {
23+
#if defined(STDLIB_OS_BYTE_ORDER)
2324
#if STDLIB_OS_BYTE_ORDER == STDLIB_OS_BYTE_ORDER_LITTLE_ENDIAN
2425
printf( "Platform is little-endian...\n" );
2526
#elif STDLIB_OS_BYTE_ORDER == STDLIB_OS_BYTE_ORDER_BIG_ENDIAN
2627
printf( "Platform is big-endian...\n" );
2728
#else
2829
printf( "Platform endianness is either mixed-endian or unknown...\n" )
2930
#endif
31+
#endif
3032
}

0 commit comments

Comments
 (0)