nicolasWDC opened a new issue, #19108:
URL: https://github.com/apache/nuttx/issues/19108

   ### Description / Steps to reproduce the issue
   
   ## Description
   
   In NuttX 12.13.0, `pthread_cond_t` is defined as `struct pthread_cond_s` 
with three fields:
   
   ```c
   struct pthread_cond_s
   {
     sem_t sem;
     clockid_t clockid;
     int wait_count;
   };
   ```
   
   However, `PTHREAD_COND_INITIALIZER` only initializes the first two fields:
   
   ```c
   #define PTHREAD_COND_INITIALIZER {SEM_INITIALIZER(0), CLOCK_REALTIME }
   ```
   
   As a result, builds using `-Wmissing-field-initializers` emit a warning when 
a condition variable is statically initialized with `PTHREAD_COND_INITIALIZER`.
   
   ## Observed warning
   
   ```text
   warning: missing initializer for member 'pthread_cond_s::wait_count' 
[-Wmissing-field-initializers]
   ```
   
   ## Expected behavior
   
   `PTHREAD_COND_INITIALIZER` should fully initialize all fields of `struct 
pthread_cond_s`.
   
   ## Root cause
   
   `struct pthread_cond_s` contains:
   
   ```c
   sem_t sem;
   clockid_t clockid;
   int wait_count;
   ```
   
   but the macro initializes only:
   
   ```c
   sem
   clockid
   ```
   
   leaving `wait_count` without an explicit initializer.
   
   ## Proposed fix
   
   Update the initializer to include `wait_count = 0`:
   
   ```c
   #define PTHREAD_COND_INITIALIZER {SEM_INITIALIZER(0), CLOCK_REALTIME, 0}
   ```
   
   This matches the structure layout and removes the warning.
   
   ## Validation
   
   A minimal compile test using:
   
   ```c
   #include <pthread.h>
   
   pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
   ```
   
   now builds without the `pthread_cond_s::wait_count` missing-initializer 
warning.
   
   
   ### On which OS does this issue occur?
   
   [OS: Linux]
   
   ### What is the version of your OS?
   
   Ubuntu 22.04
   
   ### NuttX Version
   
   12.13.0
   
   ### Issue Architecture
   
   [Arch: arm]
   
   ### Issue Area
   
   [Area: Posix]
   
   ### Host information
   
   _No response_
   
   ### Verification
   
   - [x] I have verified before submitting the report.


-- 
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