fix(posix): keep shim header nullptr behind __cplusplus guard

The earlier `style(posix): use nullptr in Windows shim headers` change
silenced clang-tidy hicpp-use-nullptr by writing `nullptr` directly into
the shim header bodies. That worked from C++ TUs but broke Windows SITL
on every C TU that includes those shims (e.g. sitl_led.c via
px4_platform_common/log.h pulling in time.h):

  windows_shim/time.h(109): error C2065: 'nullptr': undeclared identifier
  windows_shim/time.h:109:41: error: 'nullptr' undeclared

`nullptr` is a C++ keyword and only became a C23 keyword; pre-C23 C
treats it as an undeclared identifier. Add a small `__cplusplus`-guarded
fall-back macro at the top of each affected shim header so the inline
bodies stay valid from C while preserving the lint-clean spelling for
C++ callers. No behavior change.

Affected headers:
- platforms/posix/include/windows_shim/time.h
- platforms/posix/include/windows_shim/libgen.h
- platforms/posix/include/windows_shim/dirent.h
- platforms/posix/include/windows_shim/poll.h

Verified locally with MSVC by building drivers_board (sitl_led.c
compiles clean).

Signed-off-by: Nuno Marques <n.marques21@hotmail.com>
This commit is contained in:
Nuno Marques
2026-05-07 16:03:16 -07:00
parent 9e3c1da7fc
commit abd1adf443
4 changed files with 29 additions and 0 deletions
@@ -51,6 +51,13 @@
#include <string.h>
#include <errno.h>
/* This header is consumed from both C and C++ translation units. Provide a
* fall-back macro so the inline shim bodies below can spell `nullptr` while
* remaining valid in C, where `nullptr` is reserved before C23. */
#if !defined(__cplusplus) && !defined(nullptr)
# define nullptr NULL
#endif
#ifndef NAME_MAX
#define NAME_MAX 260
#endif
@@ -42,6 +42,13 @@
#include <string.h>
/* This header is consumed from both C and C++ translation units. Provide a
* fall-back macro so the inline shim bodies below can spell `nullptr` while
* remaining valid in C, where `nullptr` is reserved before C23. */
#if !defined(__cplusplus) && !defined(nullptr)
# define nullptr NULL
#endif
#ifdef __cplusplus
extern "C" {
#endif
@@ -50,6 +50,13 @@
#include <winsock2.h>
#include <windows.h>
/* This header is consumed from both C and C++ translation units. Provide a
* fall-back macro so the inline shim bodies below can spell `nullptr` while
* remaining valid in C, where `nullptr` is reserved before C23. */
#if !defined(__cplusplus) && !defined(nullptr)
# define nullptr NULL
#endif
#ifdef __cplusplus
extern "C" {
#endif
@@ -42,6 +42,14 @@
#ifdef _WIN32
/* This header is consumed from both C and C++ translation units (e.g.
* sitl_led.c on Windows SITL). Use a fall-back macro so the inline shim
* bodies below can spell `nullptr` while remaining valid in C, where
* `nullptr` is reserved before C23. */
#if !defined(__cplusplus) && !defined(nullptr)
# define nullptr NULL
#endif
#if defined(_MSC_VER) && !defined(__clang__)
#if defined(__has_include)
# if __has_include(<../ucrt/time.h>)