apache / nuttx

Apache NuttX is a mature, real-time embedded operating system (RTOS)
https://nuttx.apache.org/
Apache License 2.0
2.79k stars 1.16k forks source link

Is z80 compiler still not support CONFIG_CPP_HAVE_VARARGS? #956

Closed xiaoxiang781216 closed 4 years ago

xiaoxiang781216 commented 4 years ago

I saw that log related code check CONFIG_CPP_HAVE_VARARGS, but other function e.g. mq_open/ioctl/fcntl/printf doesn't. I am curious how z80 can pass the compile.

patacongo commented 4 years ago

The refers only VARARGS are used in preprocessor macros. Like in debug.h:

 104 #ifdef CONFIG_CPP_HAVE_VARARGS
 138 #  define _info(format, ...) \
 139    __arch_syslog(LOG_INFO, EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__)
 722 #else /* CONFIG_CPP_HAVE_VARARGS */
 739 #  define _info       (void)
1320 #endif /* CONFIG_CPP_HAVE_VARARGS */

This has nothing to do with the compiler. It is a feature of the C preprocessor. This is not a problem for the SDCC toolchain used with z80 and z180 because SDCC uses the same GNU pre-processor as does GCC. However, it is a problem for the ZDS-II toolchain which use a different pre-processor and cannot handled pre-processor macros with a variable number of arguments.

The setting CONFIG_CPP_HAVE_VARARGS only applies to the pre-processor and has nothing to do with variadic C functions with is part of the C standard and is handled by all C compiler.

Perhaps you referring to these functions:

1617 #ifndef CONFIG_CPP_HAVE_VARARGS
1618 #ifdef CONFIG_DEBUG_ALERT
1619 void _alert(const char *format, ...);
1620 #endif
1621
1622 #ifdef CONFIG_DEBUG_ERROR
1623 void _err(const char *format, ...);
1624 #endif
1625
1626 #ifdef CONFIG_DEBUG_WARN
1627 void _warn(const char *format, ...);
1628 #endif
1629
1630 #ifdef CONFIG_DEBUG_INFO
1631 void _info(const char *format, ...);
1632 #endif
1633 #endif /* CONFIG_CPP_HAVE_VARARGS */

Those are needed because if the C-preprocessor cannot handled variadic C macros, then the _err, _warn, and _info macros cannot be used . In that case, these functions must be implemented as real C functions. That should be only for the ZDS-II toolchain.

xiaoxiang781216 commented 4 years ago

Thanks, got the CONFIG_CPP_HAVE_VARARGS meaning.

patacongo commented 4 years ago

There are other issues with z80 and z180: I have not verified that they build correctly with the latest configurations that always assume we can pass structures as arguments. That is supposed to work with the lastest SDCC toolchain, but I have not yet tried. I added this warning to the README file for both of these architectures:

IMPORTANT NOTE as of 2020-4-11:  Support for CONFIG_CAN_PASS_STRUCTS was
removed in NuttX-9.0.  This was necessary to enforce some POSIX interface
compliance but also means that ALL older SDCC versions will no long build
with NuttX.  I have been told that the newest SDCC compilers can indeed
pass structure and union parameters and return values.  If that is correct,
then perhaps the newer SDCC compilers will be used.  Otherwise, it will be
necessary to use some other, more compliant compiler.

I think that z80 is no longer a viable platform because of the 16-bit address space. But the other variants are still good options for retro computing people includin the z180 which has an MMU and the z380 which can support up to a 32-bit address space. Also the new newer ez80 which handles a 24-bit address space (but does not use SDCC).