Questions tagged [pragma]

The #pragma directives offer a way for each compiler to offer machine- and operating system-specific features while retaining overall compatibility with the C and C++ languages.

Each implementation of C and C++ supports some features unique to its host machine or operating system. Some programs, for instance, need to exercise precise control over the memory areas where data is placed or to control the way certain functions receive parameters. The #pragma directives offer a way for each compiler to offer machine- and operating system-specific features while retaining overall compatibility with the C and C++ languages. Pragmas are machine- or operating system-specific by definition, and are usually different for every compiler.

From MSDN

761 questions
31
votes
1 answer

Suppress -Wunknown-pragmas warning in GCC

I try to ignore warnings coming from some 3rd party header files like this: #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunknown-pragmas" #pragma GCC diagnostic ignored "-Wreorder" #include #pragma GCC…
Robert Hegner
  • 9,014
  • 7
  • 62
  • 98
29
votes
4 answers

List of #pragma warning disable codes and what they mean

The syntax for disabling warnings is as follows: #pragma warning disable 414, 3021 Or, expressed more generally: #pragma warning disable [CSV list of numeric codes] Is there a list of these numeric codes and the description of the warning that…
Garrett
  • 1,750
  • 2
  • 16
  • 23
28
votes
3 answers

how to use #pragma clang diagnostics

I know that #pragma clang diagnostics can be used for ignoring some warnings generated by clang. But I don't know how to use this correctly. For example, for an unused variable warning we can avoid warning by #pragma clang diagnostic push #pragma…
Johnykutty
  • 12,091
  • 13
  • 59
  • 100
27
votes
2 answers

In GCC, how can I mute the '-fpermissive' warning?

I am including a file from a third-party library that raises an error that can be downgraded to a warning with -fpermissive. But because I do not want to "pollute" my compilation log with these warnings, I want to completely disable this…
piwi
  • 5,136
  • 2
  • 24
  • 48
25
votes
3 answers

Is there a way to get the constraints of a table in SQLite?

The command pragma table_info('tablename') lists the columns information and pragma foreign_key_list('tablename') the foreign keys. How can I display other constraints (check, unique) of a table? Only parsing the field "sql" of the table…
fran
  • 1,119
  • 1
  • 10
  • 27
25
votes
1 answer

How to disable all warnings using pragma directives in GCC

I am seeking for a way to suppress all possible warnings that i may get with Gcc with pragma directives. I had made some guard macros that help me silence 3rd party headers from warnings, and for now they work like charm for msvc and clang. I am…
Fr0stBit
  • 1,455
  • 1
  • 13
  • 22
24
votes
2 answers

How do I show the value of a #define at compile time in gcc

So far I've got as far as: #define ADEFINE "23" #pragma message ("ADEFINE" ADEFINE) Which works, but what if ADEFINE isn't a string? #define ADEFINE 23 #pragma message ("ADEFINE" ADEFINE) causes: warning: malformed ‘#pragma message’,…
John Lawrence Aspden
  • 17,124
  • 11
  • 67
  • 110
24
votes
2 answers

When to use Pragma Pure/Preelaborate

Is there a set of general rules/guidelines that can help to understand when to prefer pragma Pure, pragma Preelaborate, or something else entirely? The rules and definitions presented in the standard (Ada 2012), are a little heavy-going and I'd be…
Anthony
  • 12,177
  • 9
  • 69
  • 105
23
votes
3 answers

How do people handle warning C4793: 'some_function' : function compiled as native?

I'm using the OpenCV library and one of its header files, cxoperations.hpp, generates "warning C4793: 'anonymous namespace'::CV_XADD' : function compiled as native", if my C++ project is compiled with CLR support. I can prevent the warning by…
Michael Repucci
  • 1,633
  • 2
  • 19
  • 35
23
votes
8 answers

What code have you written with #pragma you found useful?

I've never understood the need of #pragma once when #ifndef #define #endif always works. I've seen the usage of #pragma comment to link with other files, but setting up the compiler settings was easier with an IDE. What are some other usages of…
Xavier Ho
  • 17,011
  • 9
  • 48
  • 52
22
votes
3 answers

What is the scope of a pragma directive?

What is the scope of a pragma directive? For example, if I say #pragma warning(disable: 4996) in a header file A that is included from a different file B, will that also disable all those warnings inside B? Or should I enable the warning at the end…
fredoverflow
  • 256,549
  • 94
  • 388
  • 662
22
votes
2 answers

do I put [[maybe unused]] on function declarations or definitions?

C++17 introduces the attribute [[maybe_unused]]. I assume this a standardized version of GCC and Clang's: __attribute__((unused)). For unused functions that I don't want to see a warning from, should I be specifying the attribute on function…
Trevor Hickey
  • 36,288
  • 32
  • 162
  • 271
22
votes
4 answers

How to hint to GCC that a line should be unreachable at compile time?

It's common for compilers to provide a switch to warn when code is unreachable. I've also seen macros for some libraries, that provide assertions for unreachable code. Is there a hint, such as through a pragma, or builtin that I can pass to GCC (or…
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
22
votes
1 answer

How to make CLion use "#pragma once" instead of "ifndef ... def ..." by default for new header files?

By default, CLion will add the following lines to a newly created header file: #ifndef SOME_NAME_H #define SOME_NAME_H .... your code here #endif //SOME_NAME_H But I like #pragma once more. How can I configure CLion so that it uses #pragma once by…
a06e
  • 18,594
  • 33
  • 93
  • 169
22
votes
5 answers

Is is possible to disable this warning in clang? warning: #pragma once in main file

warning: #pragma once in main file We're running our headers through clang to get a partial AST. Is it possible to disable that warning?
kylawl
  • 310
  • 1
  • 2
  • 9
1 2
3
50 51