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

Possible wrong code #8968

Closed
drhaozhong opened this issue Apr 6, 2023 · 1 comment
Closed

Possible wrong code #8968

drhaozhong opened this issue Apr 6, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@drhaozhong
Copy link

The code is as follows:

`struct attribute ((aligned (8))) S8 { char a[8]; };
struct attribute ((packed)) S1 { struct S8 s8; };

char a[_Alignof(struct S8)] = {0};
char b[_Alignof(struct S1)] = {0};`

This code is compiled into a size 8 array for a and size 1 array for b. Alignof is inconsistent, which i'd expect to be an error (or warning at least).

Here, gcc will warn the errors:

:4:17: error: expected primary-expression before 'struct' 4 | char a[_Alignof(struct S8)] = {0}; | ^~~~~~ :4:8: error: '_Alignof' was not declared in this scope 4 | char a[_Alignof(struct S8)] = {0}; | ^~~~~~~~ :5:17: error: expected primary-expression before 'struct' 5 | char b[_Alignof(struct S1)] = {0}; | ^~~~~~ :5:8: error: '_Alignof' was not declared in this scope 5 | char b[_Alignof(struct S1)] = {0}; | ^~~~~~~~ Compiler returned: 1
@drhaozhong drhaozhong added the bug Something isn't working label Apr 6, 2023
@dm-vodopyanov
Copy link
Contributor

Closing due to #8967 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants