954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

about #pragma

Does anybody knows about #pragma
where they are used and what is the significance in using them.
If anybody knows about please reply. :?:

brnprasad630
Newbie Poster
6 posts since Aug 2004
Reputation Points: 11
Solved Threads: 0
 

#pragma is usally used to set compiler options within the source,like telling it to link to a static lib before compiling.That stuff usally need one to make a project but with an #pragma it's quite easy if you are in a hurry.

Oh,it's syntax is usually compiler specific.For example in Borland C++,to link to a lib :
#pragma comment (lib,"path to lib")

Look in your compiler's docs to get more specific info.

FireNet
Posting Whiz in Training
258 posts since May 2004
Reputation Points: 108
Solved Threads: 7
 

Hi Brnprasad630,

with the #pragma directive, you can use implementation-specific directives
of the form:

#pragma

With #pragma, we can define whatever directives it desires without
interfering with other compilers that support #pragma.

If the compiler doesn't recognize , it ignores the #pragma
directive without an error or warning message.

C supports the following #pragma directives:

#pragma argsused #pragma exit #pragma inline #pragma option
#pragma saveregs #pragma startup #pragma warn

thanking you...
Rishi

rishiraj_bayerd
Newbie Poster
16 posts since Jul 2004
Reputation Points: 13
Solved Threads: 0
 

If you are using VC, look in help for #pragma and there's a nice list. For other compilers, their help system should also have a list of all the pragmas.

Generally pragmas help direct the compiler how to compile your code. For example, there will be pragmas to control the optimizer. This way you can turn optimization ON or OFF around certain functions. There are usually pragmas to stop compilation or put out a message to the compiler listing.

#ifdef USE_CAT
    #pragma message("Using CAT")
#else
    #pragma message("Using DOG")
#endif
Chainsaw
Posting Pro in Training
436 posts since Jun 2004
Reputation Points: 36
Solved Threads: 11
 

Hi Thanks for the valuable information
thanks and regards
prasad

Hi Brnprasad630,

with the #pragma directive, you can use implementation-specific directives of the form:

#pragma

With #pragma, we can define whatever directives it desires without interfering with other compilers that support #pragma.

If the compiler doesn't recognize , it ignores the #pragma directive without an error or warning message.

C supports the following #pragma directives:

#pragma argsused #pragma exit #pragma inline #pragma option #pragma saveregs #pragma startup #pragma warn

thanking you... Rishi

brnprasad630
Newbie Poster
6 posts since Aug 2004
Reputation Points: 11
Solved Threads: 0
 

If you are using VC, look in help for #pragma and there's a nice list. For other compilers, their help system should also have a list of all the pragmas.

Generally pragmas help direct the compiler how to compile your code. For example, there will be pragmas to control the optimizer. This way you can turn optimization ON or OFF around certain functions. There are usually pragmas to stop compilation or put out a message to the compiler listing.

#ifdef USE_CAT
    #pragma message("Using CAT")
#else
    #pragma message("Using DOG")
#endif

Dear ChainSaw,
I wanted to know where will the selected message will be printed?
The "Using CAT" or "Using DOG" at your example...
At the Screen? At the Output message in the Visual Studio?
Or, as an "error message" output on the screen?

Can you give me a working example for it, and how it work...

Thanx In Advance!!
TheAgent1982

TheAgent1982
Newbie Poster
5 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
 

I have got that line:

#pragma message("This is my message")

I wanted to know where will the selected message will be printed?
At the Screen? At the Output message in the Visual Studio?
Or, as an "error message" output on the screen?

Can you give me a working example for it, and how it work...

Thanx In Advance!!
TheAgent1982

TheAgent1982
Newbie Poster
5 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
 

>I wanted to know where will the selected message will be printed?
It's a part of the preprocessor, therefore it's a compile-time operation. Logically, you can expect the message to be printed in the compiler's output. In Visual Studio that's the output window (Ctrl+Alt+O).

>Can you give me a working example for it, and how it work...

#include <iostream>

#pragma message("This is a test")

int main()
{
  std::cout<<"Hello, world!\n";
}

This is in the output window (I've highlighted the message):

1>------ Build started: Project: Test, Configuration: Debug Win32 ------
1>Compiling...
1>main.cpp
1>This is a test
1>Build log was saved at "file://c:\C++ Projects\Test\Test\Debug\BuildLog.htm"
1>Test - 0 error(s), 0 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

Thank you very much!
Its really helps...

TheAgent1982
Newbie Poster
5 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You