How to silence a warning in Swift?
As of 2022, Xcode 14.x, Swift 5.x, the consensus is that there is no direct way to achieve that. I’ll update/edit this answer if Apple adds the feature. Put it in your wish list for WWDC 2023!
As of 2022, Xcode 14.x, Swift 5.x, the consensus is that there is no direct way to achieve that. I’ll update/edit this answer if Apple adds the feature. Put it in your wish list for WWDC 2023!
A directive like #pragma once is not trivial to define in a fully portable way that has clear an unambiguous benefits. Some of the concepts for which it raises questions are not well defined on all systems that support C, and defining it in a simple way might provide no benefit over conventional include guards. … Read more
This will work with multiple compilers (and different versions of compilers). Header “push” #if defined(__clang__) # pragma clang diagnostic push #endif #if defined(_MSC_VER) # pragma warning(push) #endif #if defined(YOUR_FAVORITE_COMPILER) # pragma your compiler push warning #endif Header “pop” #if defined(__clang__) # pragma clang diagnostic pop #endif #if defined(_MSC_VER) # pragma warning(pop) #endif Some warning #if … Read more
#pragma comment is a compiler directive which indicates Visual C++ to leave a comment in the generated object file. The comment can then be read by the linker when it processes object files. #pragma comment(lib, libname) tells the linker to add the ‘libname’ library to the list of library dependencies, as if you had added … Read more
#pragma is for compiler directives that are machine-specific or operating-system-specific, i.e. it tells the compiler to do something, set some option, take some action, override some default, etc. that may or may not apply to all machines and operating systems. See msdn for more info.
GCC gives you a few different ways of handling this: Use #pragma directives, like #pragma GCC optimize (“string”…), as seen in the GCC docs. Note that the pragma makes the optimizations global for the remaining functions. If you used #pragma push_options and pop_options macros cleverly, you could probably define this around just one function like … Read more
#pragma warning( push ) #pragma warning( disable : 4101) // Your function #pragma warning( pop )
If you’re using c99 or c++0x there is the pragma operator, used as _Pragma(“argument”) which is equivalent to #pragma argument except it can be used in macros (see section 6.10.9 of the c99 standard, or 16.9 of the c++0x final committee draft) For example, #define STRINGIFY(a) #a #define DEFINE_DELETE_OBJECT(type) \ void delete_ ## type ## … Read more
This is possible in GCC since version 4.6, or around June 2010 in the trunk. Here’s an example: #pragma GCC diagnostic push #pragma GCC diagnostic error “-Wuninitialized” foo(a); /* error is given for this one */ #pragma GCC diagnostic push #pragma GCC diagnostic ignored “-Wuninitialized” foo(b); /* no diagnostic for this one */ #pragma GCC … Read more