Utils: Add macro for C++ default arguments in C headers
This macro allows defining a default argument for when the translation unit is compiled in C++. Otherwise (in C), the argument has to be passed explicitly. A couple of benefits: * Default arguments are a nice quality-of-life feature in C++. It's annoying if these can't be used in C++ files, just because the header with the function declaration still needs to be C compatible. * Adds useful information to the API declaration. E.g. that an argument can be nullptr. * Should help us to move to using default arguments more, helping readability (arguably) Used in D14653. Reviewed By: LazyDodo Differential Revision: https://developer.blender.org/D14654
This commit is contained in:
parent
96bdd65e74
commit
5c5ec837b3
|
@ -812,6 +812,16 @@ extern bool BLI_memory_is_zero(const void *arr, size_t arr_size);
|
|||
# define ENUM_OPERATORS(_type, _max)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Utility so function declarations in C headers can use C++ default arguments. The default is then
|
||||
* available when included in a C++ file, otherwise the argument has to be set explicitly.
|
||||
*/
|
||||
#ifdef __cplusplus
|
||||
# define CPP_ARG_DEFAULT(default_value) = default_value
|
||||
#else
|
||||
# define CPP_ARG_DEFAULT(default_value)
|
||||
#endif
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
|
Loading…
Reference in New Issue