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

__STDC_VERSION__ macro not always defined #116

Closed
ilanbiala opened this issue Sep 2, 2020 · 4 comments
Closed

__STDC_VERSION__ macro not always defined #116

ilanbiala opened this issue Sep 2, 2020 · 4 comments

Comments

@ilanbiala
Copy link

I'm trying to use this library in a project with g++, and it seems that __STDC_VERSION__ is not defined when compiling C++ (https://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html). This seems like it poses an issue where:

  1. https://github.com/j123b567/scpi-parser/blob/master/libscpi/inc/scpi/cc.h#L44-L55 does not define C99
  2. https://github.com/j123b567/scpi-parser/blob/master/libscpi/inc/scpi/cc.h#L107-L109 then does not define HAVE_STDBOOL
  3. https://github.com/j123b567/scpi-parser/blob/master/libscpi/inc/scpi/cc.h#L161-L163 then defines HAVE_STDBOOL to be 0
  4. #if !HAVE_STDBOOL
    typedef unsigned char bool;
    #endif
    then defines a typedef for bool, which causes a redeclaration error in C++:
../libscpi/inc/scpi/types.h:54:27: error: redeclaration of C++ built-in type 'bool' [-fpermissive]
   54 |     typedef unsigned char bool;
      |

Should __cplusplus be used instead if it is defined to determine which language standard to define for the rest of cc.h? __cplusplus should also have values like 199711L and 201103L.

@j123b567
Copy link
Owner

j123b567 commented Sep 2, 2020

You can always define HAVE_STDBOOL=1 yourself - on command line or in scpi_user_config.h so you can try if it fixes the compilation.

Feel free to provide PR which solve this.

@MisterHW
Copy link
Contributor

MisterHW commented Jul 28, 2021

I think I'm getting away with using

#if (!HAVE_STDBOOL) && (!_GLIBCXX_HAVE_STDBOOL_H)
    typedef unsigned char bool;
#endif

p.s.: as per https://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-html-USERS-4.2/c++config_8h.html , one should not use _GLIBCXX_HAVE_STDBOOL_H directly, but this might be a case where it's warranted.

@j123b567
Copy link
Owner

C++98 should have stdbool.h so should be fixed by #139

@j123b567
Copy link
Owner

Please reopen if it is still an issue.

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

No branches or pull requests

3 participants