Unbalanced parentheses using __attribute__ in g ++

Today I tried to work on a project that I developed some time ago. I was surprised when I encountered a compilation error, since I successfully compiled my project using g ++.

This short fragment reproduces the line in which the error was detected:

int main() { __attribute__((aligned(16)) char arr[5]; } 

What causes this error:

 test.cpp:2:32: error: expected ')' __attribute__((aligned(16)) char arr[5]; ^ ) 

As you can see, there is a mournful bracket. There are three '(' and two ')'. This clearly looks like a compilation error actually occurs.

Is this a valid use of this keyword? I can't seem to find anything in the documentation , which indicates that it is.

I am using g ++ 4.5.2 and clang 2.8.

Note that this error is detected when using gcc instead of g ++.

+6
source share
1 answer

This will be a compiler error. The compiler sees __attribute__ followed by two opening parentheses, some other tokens, and then two closing parentheses, which is probably the โ€œdefinitionโ€ of what __attribute__ should look like, for example

<attribute> :: = __attribute__ '((' something '))'

I assume that the tokens between them are interpreted as aligned(16 and by some miracle they still work.

+3
source

Source: https://habr.com/ru/post/915867/


All Articles