/* C interface for result
-(C) 2017-2020 Niall Douglas <http://www.nedproductions.biz/> (6 commits)
+(C) 2017-2022 Niall Douglas <http://www.nedproductions.biz/> (6 commits)
File Created: Aug 2017
#include <stdint.h> // for intptr_t
-#define BOOST_OUTCOME_C_DECLARE_RESULT(ident, R, S) \
- struct cxx_result_##ident \
- { \
- R value; \
- unsigned flags; \
- S error; \
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#define BOOST_OUTCOME_C_DECLARE_RESULT(ident, R, S) \
+ struct cxx_result_##ident \
+ { \
+ union \
+ { \
+ R value; \
+ S error; \
+ }; \
+ unsigned flags; \
}
#define BOOST_OUTCOME_C_RESULT(ident) struct cxx_result_##ident
#define BOOST_OUTCOME_C_RESULT_ERROR_IS_ERRNO(r) (((r).flags & (1U << 4U)) == (1U << 4U))
-/***************************** <system_error2> support ******************************/
+ /***************************** <system_error2> support ******************************/
-#define BOOST_OUTCOME_C_DECLARE_STATUS_CODE(ident, value_type) \
- struct cxx_status_code_##ident \
- { \
- void *domain; \
- value_type value; \
+#define BOOST_OUTCOME_C_DECLARE_STATUS_CODE(ident, value_type) \
+ struct cxx_status_code_##ident \
+ { \
+ void *domain; \
+ value_type value; \
};
#define BOOST_OUTCOME_C_STATUS_CODE(ident) struct cxx_status_code_##ident
+#define BOOST_OUTCOME_C_DECLARE_RESULT_STATUS_CODE(ident, R, S) \
+ struct cxx_result_status_code_##ident \
+ { \
+ R value; \
+ unsigned flags; \
+ S error; \
+ }
-struct cxx_status_code_posix
-{
- void *domain;
- int value;
-};
-#define BOOST_OUTCOME_C_DECLARE_RESULT_ERRNO(ident, R) BOOST_OUTCOME_C_DECLARE_RESULT(posix_##ident, R, struct cxx_status_code_posix)
-#define BOOST_OUTCOME_C_RESULT_ERRNO(ident) BOOST_OUTCOME_C_RESULT(posix_##ident)
+#define BOOST_OUTCOME_C_RESULT_STATUS_CODE(ident) struct cxx_result_status_code_##ident
-struct cxx_status_code_system
-{
- void *domain;
- intptr_t value;
-};
-#define BOOST_OUTCOME_C_DECLARE_RESULT_SYSTEM(ident, R) BOOST_OUTCOME_C_DECLARE_RESULT(system_##ident, R, struct cxx_status_code_system)
-#define BOOST_OUTCOME_C_RESULT_SYSTEM(ident) BOOST_OUTCOME_C_RESULT(system_##ident)
+
+ struct cxx_status_code_posix
+ {
+ void *domain;
+ int value;
+ };
+#define BOOST_OUTCOME_C_DECLARE_RESULT_ERRNO(ident, R) BOOST_OUTCOME_C_DECLARE_RESULT_STATUS_CODE(posix_##ident, R, struct cxx_status_code_posix)
+#define BOOST_OUTCOME_C_RESULT_ERRNO(ident) BOOST_OUTCOME_C_RESULT_STATUS_CODE(posix_##ident)
+
+ struct cxx_status_code_system
+ {
+ void *domain;
+ intptr_t value;
+ };
+#define BOOST_OUTCOME_C_DECLARE_RESULT_SYSTEM(ident, R) BOOST_OUTCOME_C_DECLARE_RESULT_STATUS_CODE(system_##ident, R, struct cxx_status_code_system)
+#define BOOST_OUTCOME_C_RESULT_SYSTEM(ident) BOOST_OUTCOME_C_RESULT_STATUS_CODE(system_##ident)
+
+#ifdef __cplusplus
+}
+#endif
#endif