RE: Proposal: Add more compile-time asserts to exposeinconsistencies.
От | Smith, Peter |
---|---|
Тема | RE: Proposal: Add more compile-time asserts to exposeinconsistencies. |
Дата | |
Msg-id | 201DD0641B056142AC8C6645EC1B5F62014B92C7C1@SYD1217 обсуждение исходный текст |
Ответ на | Re: Proposal: Add more compile-time asserts to exposeinconsistencies. (Andres Freund <andres@anarazel.de>) |
Ответы |
Re: Proposal: Add more compile-time asserts to exposeinconsistencies.
|
Список | pgsql-hackers |
From: Andres Freund <andres@anarazel.de> Sent: Tuesday, 1 October 2019 3:14 AM >I wonder if defining the fallback static assert code to something like > extern void static_assert_func(int static_assert_failed[(condition) ? 1 : -1]); isn't a solution, however. I *think* that'sstandard C. Seems to work at least with gcc, clang, msvc, icc. > >Re standard: C99's "6.7 Declarations" + 6.7.1 defines 'declaration' to include extern specifiers and in 6.7.1 5) says "Thedeclaration of an identifier for a function that has block scope shall have >no explicit storage-class specifier otherthan extern.". And "6.8 Statements and blocks", via "6.8.2 Compound statement" allows declarations in statements. > >You can play with a good few compilers at: https://godbolt.org/z/fl0Mzu I liked your idea of using an extern function declaration for implementing the file-scope compile-time asserts. AFAIK itis valid standard C. Thank you for the useful link to that compiler explorer. I tried many scenarios of the new StaticAssertDecl and all seemedto work ok. https://godbolt.org/z/fDrmXi The patch has been updated accordingly. All assertions identified in the original post are now adjacent the global variablesthey are asserting. Kind Regards -- Peter Smith Fujitsu Australia
Вложения
В списке pgsql-hackers по дате отправления: