Timeline for Is __attribute__ portable across compilers?
Current License: CC BY-SA 4.0
11 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Aug 16, 2023 at 1:50 | vote | accept | user129393192 | ||
Aug 6, 2023 at 2:26 | answer | added | Nate Eldredge | timeline score: 2 | |
Aug 5, 2023 at 21:32 | comment | added | Mini |
I'd just like to add that even if it works on those two compilers, I don't believe the syntax __attribute__ is specified in the C99 standard, so you'd really just have to test each and every compiler. Additionally, many compilers do not fully comply with the standard...
|
|
Aug 5, 2023 at 19:14 | comment | added | Some programmer dude | Also, when you start using a C23-capable compiler, I urge you to replace as many custom attributes as possible with the (standard attributes](en.cppreference.com/w/c/language/attributes). | |
Aug 5, 2023 at 19:12 | comment | added | Some programmer dude |
Yes, both GCC and Clang have __attribute__ . But there might be differences in both which attributes are supported and their semantics. Before using an attribute please study the documentation of both compilers carefully. And note that MSVC does not (as far as I know) have __attribute__ , it have its own syntax and special keywords (some which have been copied by at least GCC IIRC).
|
|
Aug 5, 2023 at 18:31 | comment | added | user129393192 |
So both do have __attribute__ in all cases? @Someprogrammerdude. I specifically meant portable across gcc and clang .
|
|
Aug 5, 2023 at 18:19 | comment | added | Bob Goddard | If all you are doing is compiling, then you are not testing. Testing means running and throwing test data at it. | |
Aug 5, 2023 at 18:18 | comment | added | Some programmer dude |
Unless part of the specification, nothing beginning with an underscore should be considered portable. It's often used for implementation- and compiler-specific things. Clang modeled lots of their non-portable things after GCC, that's why both have __attribute__ . Always check the compiler documentation whenever you see anything beginning with an underscore.
|
|
Aug 5, 2023 at 18:16 | comment | added | user129393192 | I did @Bib. And it compiles, but just because it compiles, doesn't mean it's correct. | |
Aug 5, 2023 at 18:13 | comment | added | Bob Goddard | Never assume or accept what the docs say - ALWAYS TEST! | |
Aug 5, 2023 at 18:06 | history | asked | user129393192 | CC BY-SA 4.0 |