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

static_assert is C23, rather use _Static_assert #61

Open
barracuda156 opened this issue Jan 5, 2024 · 4 comments · May be fixed by #62
Open

static_assert is C23, rather use _Static_assert #61

barracuda156 opened this issue Jan 5, 2024 · 4 comments · May be fixed by #62

Comments

@barracuda156
Copy link

static_assert is C23, so it won’t work unless the standard is forced, but _Static_assert works fine.

In file included from /opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_sysutils_blisp/blisp/work/blisp-0.0.4/lib/blisp_easy.c:3:
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_sysutils_blisp/blisp/work/blisp-0.0.4/include/blisp_struct.h:157:15: error: expected declaration specifiers or '...' before 'sizeof'
  157 | static_assert(sizeof(struct bfl_boot_header) == 176,
      |               ^~~~~~
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_sysutils_blisp/blisp/work/blisp-0.0.4/include/blisp_struct.h:158:15: error: expected declaration specifiers or '...' before string constant
  158 |               "Bootheader have wrong size");
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_sysutils_blisp/blisp/work/blisp-0.0.4/include/blisp_struct.h:167:15: error: expected declaration specifiers or '...' before 'sizeof'
  167 | static_assert(sizeof(struct blflash_segment_header) == 16,
      |               ^~~~~~
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_sysutils_blisp/blisp/work/blisp-0.0.4/include/blisp_struct.h:168:15: error: expected declaration specifiers or '...' before string constant
  168 |               "Segment header have wrong size");
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Ref: https://en.cppreference.com/w/c/language/_Static_assert

@barracuda156
Copy link
Author

barracuda156 commented Jan 5, 2024

At the same time CMakeLists ask only for C11:

set(CMAKE_C_STANDARD 11)

barracuda156 added a commit to barracuda156/blisp that referenced this issue Jan 5, 2024
@jmroot
Copy link

jmroot commented Jan 5, 2024

static_assert is C23

That's not really correct. static_assert is defined by C11 and later, it just became a keyword in C23. Prior to that it's a macro that is supposed to be defined by assert.h.

@barracuda156
Copy link
Author

barracuda156 commented Jan 5, 2024

static_assert is C23

That's not really correct. static_assert is defined by C11 and later, it just became a keyword in C23. Prior to that it's a macro that is supposed to be defined by assert.h.

Build fails for me with gcc-13 if static_assert is used and succeeds with _Static_assert, no other changes. Maybe something wrong with headers then, but I have no idea how to fix it otherwise.

@jmroot
Copy link

jmroot commented Jan 5, 2024

Yes, I never said that wouldn't work (though _Static_assert is deprecated in C23, so it may stop working in future). And yes, the headers are not C11 compliant if they don't define the macro. Another possible workaround is the one used by Python: https://github.com/python/cpython/blob/v3.12.1/Include/pymacro.h#L20-L24

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

Successfully merging a pull request may close this issue.

2 participants