casaroli opened a new pull request, #21051:
URL: https://github.com/apache/nuttx/pull/21051

   ## Summary
   
   The coding standard asks each header to define `EXTERN` (`extern "C"` for 
C++, `extern` for C) for the declarations of its global data, and to undefine 
it at its end. On master about 2600 files do that, but only about 150 of them 
declare data with `EXTERN`. Of the headers that a program can include, 1344 
define `EXTERN` and 38 use it.
   
   This was discussed on dev@: 
https://lists.apache.org/thread/g5bdodkxn82t5h15j1scyy0p9gfj09so
   
   `EXTERN` is not a reserved name. The `#undef EXTERN` at the end of the 
headers also removes a definition that a program made for its own use: Tcl's 
`tcl.h` defines `EXTERN`, `tclInt.h` then includes system headers, and Tcl's 
declarations with `EXTERN` no longer compile.
   
   The commits:
   
   1. Fix the old nxstyle errors of seven files, so that checkpatch, which 
checks whole files, does not report them.
   2. to 4. Remove the definitions that nothing uses, in `include/`, then 
`arch/` and `boards/`, then the internal headers of `drivers/`, `fs/`, 
`graphics/`, `libs/`, `net/`, `sched/` and `wireless/`: the `#undef EXTERN`, 
the two `#define EXTERN` lines and the `#else` that held one of them. The 
`extern "C"` block for C++ stays.
   5. to 7. The files that declare global data with `EXTERN` use plain `extern` 
now (20 headers of `include/`, 98 of `arch/`, mostly `irq.h`, 3 of `boards/`, 
and the internal headers). Each of these declarations is inside the `extern 
"C"` block of its header, so plain `extern` gives it C linkage in C++ too. 
`avrdx_serial.h` opened its `extern "C"` block but did not close it; it is 
closed now.
   8. `Documentation/contributing/coding_style.rst`: the template declares 
global data with `extern` inside the `extern "C"` block, and a header does not 
define a macro such as `EXTERN`.
   
   After this PR no file of nuttx defines `EXTERN` (`tools/nxstyle.c` still 
knows the word).
   
   ## Impact
   
   No change of the code that the compiler sees.
   
   Code outside nuttx (out-of-tree boards or applications) that declares data 
with `EXTERN` and relied on a NuttX header to define it no longer compiles; the 
fix is to write `extern`. No file in nuttx-apps does this.
   
   checkpatch still reports old errors in files that this PR touches but does 
not fix: the long copyright lines of `include/nuttx/fs/nfs.h`, 
`include/nuttx/net/icmpv6.h` and `include/nuttx/net/igmp.h`, mixed-case 
register names in `arch/arm/src/lpc43xx/hardware/lpc43_spifi.h`, and an 
`#include` inside the `enum` of `include/sys/syscall.h`.
   
   ## Testing
   
   A test program that defines its own `EXTERN`, includes the common headers 
(also `stdio.h`, `unistd.h` and `time.h`) and then declares data with `EXTERN`: 
on master it does not compile; with this PR it compiles and runs on 
`qemu-armv8a:knsh`. ostest exits with status 0 on `qemu-armv8a:knsh` and 
`qemu-armv8a:nsh`.
   
   Build (Make), each OK: `qemu-armv8a:nsh` with NET, IPv6, ICMPv6, IGMP and 
NFS; `qemu-armv8a:knsh`; `rv-virt:nsh64`, `rv-virt:knsh64`, `rv-virt:pnsh64`; 
`qemu-intel64:nsh`, `qemu-intel64:knsh_romfs`; `sim:nsh`, `sim:libcxxtest`; 
`esp32-devkitc:nsh`; `esp32s3-devkit:knsh`; `nucleo-f072rb:nsh`; 
`qemu-armv7a:knsh`; `mps2-an500:knsh`; `fvp-armv8r-aarch32:nsh`.
   
   This is a draft so that CI builds every configuration before review.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to