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
60
votes
3 answers

C#: Is pragma warning restore needed?

From msdn I get this: #pragma warning disable warning-list #pragma warning restore warning-list In the examples, both disable and restore are used. Is it necessary to restore if I want it disabled for a whole file? Like, if I do not restore, how…
Svish
  • 152,914
  • 173
  • 462
  • 620
60
votes
9 answers

Why isn't C/C++'s "#pragma once" an ISO standard?

I am currently working on a big project and maintaining all those include guards makes me crazy! Writing it by hand is frustrating waste of time. Although many editors can generate include guards this doesn't help much: Editor generates guard…
mip
  • 8,355
  • 6
  • 53
  • 72
53
votes
5 answers

How can I disable #pragma warnings?

While developing a C++ application, I had to use a third-party library which produced a huge amount of warnings related with a harmless #pragma directive being used. ../File.hpp:1: warning: ignoring #pragma ident In file included from…
Marcos Bento
  • 2,030
  • 4
  • 22
  • 19
52
votes
2 answers

What is the difference between parent and base in Perl 5?

There appears to be a new pragma named parent that does roughly the same thing as base. What does parent do that warrants a new (non-core) module? I am missing something?
Chas. Owens
  • 64,182
  • 22
  • 135
  • 226
48
votes
4 answers

What does #pragma once mean in C?

Possible Duplicate: #pragma - help understanding I saw the pragma many times,but always confused, anyone knows what it does?Is it windows only?
wireshark
  • 1,295
  • 2
  • 14
  • 20
48
votes
3 answers

C++: What does #pragma comment(lib, "XXX") actually do with "XXX"?

My background is C# but I have to maintain some legacy (MS) C++. In that codebase I stumpled across: #pragma comment(lib, "OtherLib700.lib") where 700 is some versioning. Besides the lib is a DLL with the same name. I first thought that the program…
steglig
  • 1,098
  • 1
  • 9
  • 15
47
votes
1 answer

Is there any reason not to use the INLINABLE pragma for a function?

The documentation states: An {-# INLINABLE f #-} pragma on a function f has the following behaviour: While INLINE says "please inline me", the INLINABLE says "feel free to inline me; use your discretion". In other words the choice is left to GHC,…
glaebhoerl
  • 7,695
  • 3
  • 30
  • 41
45
votes
1 answer

What does #pragma unroll do exactly? Does it affect the number of threads?

I'm new to CUDA, and I can't understand loop unrolling. I've written a piece of code to understand the technique __global__ void kernel(float *b, int size) { int tid = blockDim.x * blockIdx.x + threadIdx.x; #pragma unroll for(int…
Magzhan Abdibayev
  • 657
  • 1
  • 7
  • 12
44
votes
4 answers

Is there a way to disable all warnings with a pragma?

I've started a new project and have decided to make sure it builds cleanly with the /Wall option enabled. The only problem is not all 3rd party libraries (like boost) compile without warnings, so I've resorted to doing this in a shared…
Ferruccio
  • 98,941
  • 38
  • 226
  • 299
41
votes
6 answers

How can I use #pragma message() so that the message points to the file(lineno)?

In order to add 'todo' items into my code, I want to put a message in the compiler output. I would like it to look like this: c:/temp/main.cpp(104): TODO - add code to implement this in order to make use of the Visual Studio build output…
xtofl
  • 40,723
  • 12
  • 105
  • 192
39
votes
3 answers

#pragma warning disable & restore

I have used c# to create a First Project. I have many warning errors and all these warning errors are to be single Error(Internal compiler error. See the console log for more information.) For Reducing the warning errors I used #pragma Warning…
SaravanaKumar
  • 739
  • 1
  • 7
  • 17
37
votes
1 answer

GCC does not honor 'pragma GCC diagnostic' to silence warnings

We recently enabled -Wall for a project. Its enabled when GCC is at 4.7 or above (or Clang) because we can use GCC diagnostic to manage the output from the elevated warnings. We want to manage them from the source code, and not via command line…
jww
  • 97,681
  • 90
  • 411
  • 885
35
votes
3 answers

Should I still use #include guards AND #pragma once?

http://en.wikipedia.org/wiki/Pragma_once Should I still use include guards when all of these compilers support #pragma once? A lot of responses on stack overflow say to use both for compatibility, but I'm not sure if that still rings true. What…
Trevor Hickey
  • 36,288
  • 32
  • 162
  • 271
34
votes
7 answers

What could be adding "Pragma:no-cache" to my response Headers? (Apache, PHP)

I have a website which maintenance I've inherited, which is a big hairy mess. One of the things I'm doing is improving performance. Among other things, I'm adding Expires headers to images. Now, there are some images that are served through a PHP…
Daniel Magliola
  • 30,898
  • 61
  • 164
  • 243
32
votes
3 answers

#pragma once position: before or after #include's

In existing code I saw #pragma once be used after header #includes //Some_Header.h #include "header1.h" #include "header2.h" #pragma once //implementations Instead of //Some_Header.h #pragma once #include "header1.h" #include…
turoni
  • 1,345
  • 1
  • 18
  • 37
1
2
3
50 51