Skip to content

Commit

Permalink
iio.h: Remove c++ access to c only functions
Browse files Browse the repository at this point in the history
The C11 generic macros iio_attr_{read,write} cannot be accesed from a
program built with C++. Adding the __cplusplus guard for these functions
will ensure that C++ users do not accidentally use these.

Signed-off-by: Andrei-Fabian-Pop <[email protected]>
  • Loading branch information
Andrei-Fabian-Pop authored and dNechita committed Feb 17, 2025
1 parent 4537c21 commit 5953771
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/iio/iio.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,11 +362,13 @@ iio_attr_read_raw(const struct iio_attr *attr, char *dst, size_t len);
* @param ptr A pointer to a variable where the value should be stored
* @return On success, 0 is returned
* @return On error, a negative errno code is returned */
#ifndef __cplusplus
#define iio_attr_read(attr, ptr) \
_Generic((ptr), \
bool *: iio_attr_read_bool, \
long long *: iio_attr_read_longlong, \
double *: iio_attr_read_double)(attr, ptr)
#endif /* __cplusplus */

/** @brief Set the value of the given attribute
* @param attr A pointer to an iio_attr structure
Expand All @@ -382,13 +384,15 @@ iio_attr_write_raw(const struct iio_attr *attr, const void *src, size_t len);
* @param val The value to set the attribute to
* @return On success, the number of bytes written
* @return On error, a negative errno code is returned. */
#ifndef __cplusplus
#define iio_attr_write(attr, val) \
_Generic((val), \
const char *: iio_attr_write_string, \
char *: iio_attr_write_string, \
bool: iio_attr_write_bool, \
long long: iio_attr_write_longlong, \
double: iio_attr_write_double)(attr, val)
#endif /* __cplusplus */

/** @brief Retrieve the name of an attribute
* @param attr A pointer to an iio_attr structure
Expand Down

0 comments on commit 5953771

Please sign in to comment.