This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit d35336b1974876ae5adc55580c2df9baea0102b4
Author: Marco Casaroli <[email protected]>
AuthorDate: Wed Oct 28 16:24:25 2026 +0100

    tools/nxstyle: Report a definition of EXTERN in a header.
    
    The coding standard says that a header does not define a macro such as
    EXTERN: it declares global data with extern inside its extern "C"
    block.  The #undef EXTERN at the end of such a header removes a
    definition that a program made for its own use (Tcl's tcl.h defines
    EXTERN before it includes system headers).
    
    The headers of nuttx stopped defining EXTERN, but three changes that
    were merged at the same time added it again.  nxstyle now reports
    "#define EXTERN" and "#undef EXTERN" in a header, so that checkpatch
    finds a new one.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 tools/nxstyle.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/tools/nxstyle.c b/tools/nxstyle.c
index f6b66347fb0..ac6811ffcf5 100644
--- a/tools/nxstyle.c
+++ b/tools/nxstyle.c
@@ -2188,6 +2188,31 @@ int main(int argc, char **argv, char **envp)
 
                   ppline = PPLINE_OTHER;
 
+                  /* A header does not define or undefine EXTERN: its
+                   * #undef removes the definition of a program that
+                   * includes it.
+                   */
+
+                  if (g_file_type == C_HEADER &&
+                      (strncmp(&line[ii], "define", 6) == 0 ||
+                       strncmp(&line[ii], "undef", 5) == 0))
+                    {
+                      int jj = ii + (line[ii] == 'd' ? 6 : 5);
+
+                      while (line[jj] != '\0' && isspace(line[jj]))
+                        {
+                          jj++;
+                        }
+
+                      if (strncmp(&line[jj], "EXTERN", 6) == 0 &&
+                          !isalnum(line[jj + 6]) && line[jj + 6] != '_')
+                        {
+                          ERROR("Do not define EXTERN, declare global data "
+                                "with extern",
+                                lineno, jj);
+                        }
+                    }
+
                   if (strncmp(&line[ii], "define", 6) == 0)
                     {
                       ppline = PPLINE_DEFINE;

Reply via email to