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

#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.

Hi Brnprasad630,

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

#pragma <directive_name>

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

If the compiler doesn't recognize <directive_name>, 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

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

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 <directive_name>

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

If the compiler doesn't recognize <directive_name>, 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

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

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

>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 ==========
commented: That was a great example, I'll have to study the #pragma directive too +1

Thank you very much!
Its really helps...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.