Declare a Result

// Declare to C a Result with a happy value of intptr_t
CXX_DECLARE_RESULT_SYSTEM(result_int, intptr_t)

// Save oneself typing out CXX_RESULT_SYSTEM(result_int) all the time
typedef CXX_RESULT_SYSTEM(result_int) result;

// Our custom C enum
enum c_enum
{
  c_enum_not_found,
  c_enum_bad_argument
};

// Make a custom status code domain for this C enum
CXX_DECLARE_RESULT_SYSTEM_FROM_ENUM(result_int,                                // The C Result type declared above
                                    c_enum,                                    // The C enum we wish to wrap
                                    "{74ceb994-7622-3a21-07f0-b016aa705585}",  // Unique UUID for this domain
                                    // Mappings of C enum values to textual description and semantic equivalances to generic codes
                                    {c_enum::c_enum_not_found, "item not found", {errc::no_such_file_or_directory}},
                                    {c_enum::c_enum_bad_argument, "invoked wrong", {errc::invalid_argument}})

// Make helper macros
#define SUCCESS(v) CXX_MAKE_RESULT_SYSTEM_SUCCESS(result_int, (v))
#define FAILURE(v) CXX_MAKE_RESULT_SYSTEM_FROM_ENUM(result_int, c_enum, (v))
View this code on Github

The key to making C programming easy is to alias the long complex things into short easy thing. Obviously SUCCESS(expr) and FAILURE(expr) is too generic, but for the purposes of this documentation it makes thing easier.