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
310
votes
9 answers

How to disable GCC warnings for a few lines of code

In Visual C++, it's possible to use #pragma warning (disable: ...). Also I found that in GCC you can override per file compiler flags. How can I do this for "next line", or with push/pop semantics around areas of code using GCC?
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
292
votes
6 answers

What is the significance of #pragma marks? Why do we need #pragma marks?

What is the purpose of #pragma marks in Xcode? Does their location in .m files matter? Should some #pragma come before all others? Do they have to be present? Can new marks be added? Why would they be? What causes it? Is there any harm in having a…
James Raitsev
  • 92,517
  • 154
  • 335
  • 470
189
votes
5 answers

What does "#pragma comment" mean?

What does #pragma comment mean in the following? #pragma comment(lib, "kernel32") #pragma comment(lib, "user32")
user198729
  • 61,774
  • 108
  • 250
  • 348
153
votes
11 answers

Disable single warning error

Is there a way to disable just a single warning line in a cpp file with visual studio? For example, if I catch an exception and don't handle it, I get error 4101 (unreferenced local variable). Is there a way to ignore this just in that function, but…
Cookie
  • 12,004
  • 13
  • 54
  • 83
136
votes
5 answers

How to silence a warning in Swift?

I have a piece of code which is generating lots of warnings (deprecated API) Using clang* I could do: #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" ... #pragma clang diagnostic pop However this does…
Antzi
  • 12,831
  • 7
  • 48
  • 74
133
votes
10 answers

Use of #pragma in C

What are some uses of #pragma in C, with examples?
srujan
126
votes
8 answers

Is there a compiler hint for GCC to force branch prediction to always go a certain way?

For the Intel architectures, is there a way to instruct the GCC compiler to generate code that always forces branch prediction a particular way in my code? Does the Intel hardware even support this? What about other compilers or hardwares? I would…
WilliamKF
  • 41,123
  • 68
  • 193
  • 295
118
votes
4 answers

Pragma in define macro

Is there some way to embed pragma statement in macro with other statements? I am trying to achieve something like: #define DEFINE_DELETE_OBJECT(type) \ void delete_ ## type_(int handle); \ void delete_…
Anycorn
  • 50,217
  • 42
  • 167
  • 261
93
votes
4 answers

Selectively disable GCC warnings for only part of a translation unit

What's the closest GCC equivalent to this MSVC preprocessor code? #pragma warning( push ) // Save the current warning state. #pragma warning( disable : 4723 ) // C4723: potential divide by 0 // Code which would generate…
Jon-Eric
  • 16,977
  • 9
  • 65
  • 97
90
votes
2 answers

Pragmas in python

I'm reading bottle.py source code. It's a web framework, with only 3000+ lines python code. So cool. I found some code like this: class ServerAdapter(object): quiet = False def __init__(self, host='127.0.0.1', port=8080, **config): …
hhbcarl
  • 970
  • 1
  • 6
  • 8
87
votes
5 answers

Where does the word "pragma" come from?

So I know what pragma is, and what it's used for, but what is the meaning of the word itself? I've used it many times in code, but I never really knew what the word actually means or stands for.
MGSoto
  • 2,293
  • 5
  • 21
  • 29
86
votes
3 answers

What does the HTTP header Pragma: Public mean?

What does the HTTP header Pragma: Public mean?
user185631
  • 1,313
  • 1
  • 10
  • 13
85
votes
7 answers

Is using #pragma warning push/pop the right way to temporarily alter warning level?

Once in a while it's difficult to write C++ code that wouldn't emit warnings at all. Having warnings enabled is however a good idea. So it is often necessary to disable warnings around some specific construct and have them enables in all other…
sharptooth
  • 167,383
  • 100
  • 513
  • 979
84
votes
6 answers

Why isn't #pragma once automatically assumed?

What's the point of telling the compiler specifically to include the file only once? Wouldn't it make sense by default? Is there even any reason to include a single file multiple times? Why not just assume it? Is it to do with specific hardware?
Johnny Cache
  • 1,033
  • 7
  • 12
66
votes
3 answers

Tell gcc to specifically unroll a loop

How can I tell GCC to unroll a particular loop? I have used the CUDA SDK where loops can be unrolled manually using #pragma unroll. Is there a similar feature for gcc? I googled a bit but could not find anything.
Nils
  • 13,319
  • 19
  • 86
  • 108
1
2 3
50 51