nros C API
Lightweight ROS 2 client for embedded real-time systems
Loading...
Searching...
No Matches
Macros
check.h File Reference

Error-check convenience macros for the nros C API. More...

#include "rclc/types.h"
Include dependency graph for check.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define RCLC_CHECK(call)
 
#define RCLC_CHECK_LOG(file, line, expr, ret)    ((void)(file), (void)(line), (void)(expr), (void)(ret))
 
#define RCLC_CHECK_RET(call, retval)
 
#define RCLC_SOFTCHECK(call)
 

Detailed Description

Error-check convenience macros for the nros C API.

Wraps the common "call returns rcl_ret_t; on failure log and bail" pattern in one-liners so example main()s and user code don't open-code 4-line check blocks at every API site.

Pattern parity with rclc:

The macros log file:line, the literal call text, and the integer return code. Issue 0332 — the default logger is printf ONLY on a hosted target (__STDC_HOSTED__) or when RCLC_CHECK_STDIO is defined; on a freestanding embedded target it defaults to a no-op, so a no_std C node does not silently pull <stdio.h> into every TU.

Override the log function by defining RCLC_CHECK_LOG(file, line, expr, ret) before including this header (e.g. to route through a board's UART, RTT, or nros-log), or define RCLC_CHECK_STDIO to force the printf form on a freestanding target.

Copyright 2026 nros contributors Licensed under Apache-2.0

Macro Definition Documentation

◆ RCLC_CHECK

#define RCLC_CHECK (   call)
Value:
do { \
rcl_ret_t _nros_check_ret = (call); \
if (_nros_check_ret != RCL_RET_OK) { \
RCLC_CHECK_LOG(__FILE__, __LINE__, #call, _nros_check_ret); \
return; \
} \
} while (0)
#define RCL_RET_OK
Definition nros_generated.h:2965
int rcl_ret_t
Definition nros_generated.h:903

Fatal check: evaluate call once; if the returned rcl_ret_t is not RCL_RET_OK, log the failure and return from the enclosing function (which must return void or accept a bare return;).

◆ RCLC_CHECK_LOG

#define RCLC_CHECK_LOG (   file,
  line,
  expr,
  ret 
)     ((void)(file), (void)(line), (void)(expr), (void)(ret))

◆ RCLC_CHECK_RET

#define RCLC_CHECK_RET (   call,
  retval 
)
Value:
do { \
rcl_ret_t _nros_check_ret = (call); \
if (_nros_check_ret != RCL_RET_OK) { \
RCLC_CHECK_LOG(__FILE__, __LINE__, #call, _nros_check_ret); \
return (retval); \
} \
} while (0)

Like RCLC_CHECK but for callers that need a custom return value (non-void functions). Returns retval on failure.

◆ RCLC_SOFTCHECK

#define RCLC_SOFTCHECK (   call)
Value:
do { \
rcl_ret_t _nros_softcheck_ret = (call); \
if (_nros_softcheck_ret != RCL_RET_OK) { \
RCLC_CHECK_LOG(__FILE__, __LINE__, #call, _nros_softcheck_ret); \
} \
} while (0)

Non-fatal check: evaluate call once; on failure, log and continue. Use for "best effort" calls (e.g. publishing a heartbeat) where one dropped iteration shouldn't tear down the node.