Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing inttypes.h fails due to misplaced wchar_t definition #200

Closed
guberti opened this issue Jul 5, 2021 · 2 comments
Closed

Importing inttypes.h fails due to misplaced wchar_t definition #200

guberti opened this issue Jul 5, 2021 · 2 comments
Milestone

Comments

@guberti
Copy link

guberti commented Jul 5, 2021

Description of the issue:

Including inttypes.h in a .c file fails.

How to reproduce:

The issue should be easy to reproduce by just creating a importer.c file with a single line:

#include <inttypes.h>

Compiling that file will produce the following errors:

In file included from /home/guberti/Desktop/demonstrate_inttypes_bug/importer.c:1:0:
/home/guberti/.arduino15/packages/SPRESENSE/tools/spresense-sdk/2.2.1/spresense/release/nuttx/include/inttypes.h:185:31: error: unknown type name 'wchar_t'
 intmax_t  wcstoimax(FAR const wchar_t *nptr, FAR wchar_t **endptr, int base);
                               ^
/home/guberti/.arduino15/packages/SPRESENSE/tools/spresense-sdk/2.2.1/spresense/release/nuttx/include/inttypes.h:185:50: error: unknown type name 'wchar_t'
 intmax_t  wcstoimax(FAR const wchar_t *nptr, FAR wchar_t **endptr, int base);
                                                  ^
/home/guberti/.arduino15/packages/SPRESENSE/tools/spresense-sdk/2.2.1/spresense/release/nuttx/include/inttypes.h:186:31: error: unknown type name 'wchar_t'
 uintmax_t wcstoumax(FAR const wchar_t *nptr, FAR wchar_t **endptr, int base);
                               ^
/home/guberti/.arduino15/packages/SPRESENSE/tools/spresense-sdk/2.2.1/spresense/release/nuttx/include/inttypes.h:186:50: error: unknown type name 'wchar_t'
 uintmax_t wcstoumax(FAR const wchar_t *nptr, FAR wchar_t **endptr, int base);
                                                  ^

You can also use this Arduino script to reproduce the issue.

Solution

This issue arises because inttypes.h cannot find where wchar_t is defined. It tries to import stddef.h for this purpose:

https://github.com/sonydevworld/spresense-nuttx/blob/5c65b4d1e49add94270d8c515b85534559dd9fb8/include/inttypes.h#L39-L43

/****************************************************************************
 * Included Files
 ****************************************************************************/

#include <stddef.h> /* for wchar_t */

However, for reasons unknown to me stddef.h does not define wchar_t. There's a comment saying that it should, so the logical solution seems to be moving the definition of wchar_t from sys/types.h to stddef.h.

https://github.com/sonydevworld/spresense-nuttx/blob/5c65b4d1e49add94270d8c515b85534559dd9fb8/include/stddef.h#L90-L93

/*
 * NOTE: Currently the type definitions of ptrdiff_t, wchar_t, and size_t are
 *     in sys/types.h but should be moved here sometime.
 */
@SPRESENSE
Copy link
Collaborator

@guberti
Thank you for reporting the issue.

This has been already resolved in the following commit on the develop branch, and will be released in the next official version.
sonydevworld/spresense-nuttx@e99e185#diff-18fc24aec5247a51ba32867677c04c53a35eda8f3407f7d94c55318867990088

Thanks.

@SPRESENSE
Copy link
Collaborator

SDK v2.3 has been released and this issue has been resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants