Skip to content

stdbit.h: fix compilation error of generic stdc_ functions#19221

Merged
linguini1 merged 1 commit into
apache:masterfrom
michallenc:stdbit-fix
Jun 26, 2026
Merged

stdbit.h: fix compilation error of generic stdc_ functions#19221
linguini1 merged 1 commit into
apache:masterfrom
michallenc:stdbit-fix

Conversation

@michallenc

Copy link
Copy Markdown
Contributor

Summary

Generic stdc_ functions use _Generic macro, but this requires the type specific functions stdc_*_uc, stdc_*_ul and so on to be functions, not just another macro definitions.

This commit fixes the issue by ensuring all type specific functions are static inline functions, not macro definitions.

Impact

Fixes the compilation error of stdc_leading_ones, stdc_trailing_ones, stdc_count_zeros, stdc_count_ones,
stdc_has_single_bit and stdc_bit_width functions.

Testing

Testing application is here. I will create a separate merge request for tests later.

Compile errors before the fix:

Create version.h
CC:  stdbit.c In file included from stdbit.c:31:
stdbit.c: In function ‘leading_ones’:
stdbit.c:207:14: error: ‘stdc_leading_ones_uc’ undeclared (first use in this function); did you mean ‘stdc_leading_zeros_uc’?
  207 |       ret2 = stdc_leading_ones(uc);
      |              ^~~~~~~~~~~~~~~~~
stdbit.c:207:14: note: each undeclared identifier is reported only once for each function it appears in
stdbit.c: In function ‘trailing_ones’:
stdbit.c:385:14: error: ‘stdc_trailing_ones_uc’ undeclared (first use in this function); did you mean ‘stdc_trailing_zeros_uc’?
  385 |       ret2 = stdc_trailing_ones(uc);
      |              ^~~~~~~~~~~~~~~~~~
stdbit.c: In function ‘count_zeros’:
stdbit.c:830:14: error: ‘stdc_count_zeros_uc’ undeclared (first use in this function); did you mean ‘stdc_leading_zeros_uc’?
  830 |       ret2 = stdc_count_zeros(uc);
      |              ^~~~~~~~~~~~~~~~
stdbit.c: In function ‘count_ones’:
stdbit.c:919:14: error: ‘stdc_count_ones_uc’ undeclared (first use in this function)
  919 |       ret2 = stdc_count_ones(uc);
      |              ^~~~~~~~~~~~~~~
stdbit.c: In function ‘has_single_bit’:
stdbit.c:1008:14: error: ‘stdc_has_single_bit_uc’ undeclared (first use in this function); did you mean ‘has_single_bit’?
 1008 |       ret2 = stdc_has_single_bit(uc);
      |              ^~~~~~~~~~~~~~~~~~~
stdbit.c: In function ‘bit_width’:
stdbit.c:1097:14: error: ‘stdc_bit_width_uc’ undeclared (first use in this function); did you mean ‘stdc_bit_ceil_uc’?
 1097 |       ret2 = stdc_bit_width(uc);
      |              ^~~~~~~~~~~~~~
make[2]: *** [/path/to/nuttx/apps/Application.mk:330: stdbit.c.home.michal.Michal.projects.nuttx.apps.testing.libc.stdbit.o] Error 1
make[1]: *** [Makefile:54: /path/to/nuttx/apps/testing/libc/stdbit_all] Error 2
make[1]: *** Waiting for unfinished jobs....
make: *** [tools/LibTargets.mk:248: /path/to/nuttx/apps/libapps.a] Error 2
make: *** Waiting for unfinished jobs....

The application compiles and all tests pass after the fix.

Generic stdc_ functions use _Generic macro, but this requires the type
specific functions stdc_*_uc, stdc_*_ul and so on to be functions,
not just another macro definitions.

This commit fixes the issue by ensuring all type specific functions
are static inline functions, not macro definitions.

There is no change other in the functionality or implementation.

Signed-off-by: Michal Lenc <michallenc@seznam.cz>
@michallenc

Copy link
Copy Markdown
Contributor Author

ping @jerpelea for 13.0 backport

@github-actions github-actions Bot added the Size: M The size of the change in this PR is medium label Jun 26, 2026
@github-actions

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:

@linguini1 linguini1 merged commit c13914c into apache:master Jun 26, 2026
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Size: M The size of the change in this PR is medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants