Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > use of #Pragma

Reply
Thread Tools

use of #Pragma

 
 
karunesh
Guest
Posts: n/a
 
      01-23-2007
why this #pragma use very extnsivly

please tell me the usses
thaks!!
Regards,
Karuensh

 
Reply With Quote
 
 
 
 
=?iso-8859-1?q?Erik_Wikstr=F6m?=
Guest
Posts: n/a
 
      01-23-2007
On Jan 23, 8:07 am, "karunesh" <(E-Mail Removed)> wrote:
> why this #pragma use very extnsivly


Pragma directives are implementation specific and ignored on
implementations that don't understand them. Some uses that I know of is
in MS VC++ uses them instead of include-guards. I seem to recall that
they can be used on some platforms to specify alignment of members of
classes and structs. I think OpenMP uses them to indicate parts of the
code that should be parallelized. Another common usage is to set
compiler-options that could just as well have been passed as command
line options.

--
Erik Wikström

 
Reply With Quote
 
 
 
 
karunesh
Guest
Posts: n/a
 
      01-23-2007
Dear Erik ,

Thanks for a beautiful Explation .
as i know in inclusion gard we use

#ifndef _SOME_

/* Header file body */

#endif

and i remmber some where i read that #pragma can be use for structure
paddsing .
some where i also read that its also use to change in entery point of
the programe.

can you put focus on the same ..
how this can be handle

Regards,
Karuensh



Erik Wikström wrote:
> On Jan 23, 8:07 am, "karunesh" <(E-Mail Removed)> wrote:
> > why this #pragma use very extnsivly

>
> Pragma directives are implementation specific and ignored on
> implementations that don't understand them. Some uses that I know of is
> in MS VC++ uses them instead of include-guards. I seem to recall that
> they can be used on some platforms to specify alignment of members of
> classes and structs. I think OpenMP uses them to indicate parts of the
> code that should be parallelized. Another common usage is to set
> compiler-options that could just as well have been passed as command
> line options.
>
> --
> Erik Wikström


 
Reply With Quote
 
=?iso-8859-1?q?Erik_Wikstr=F6m?=
Guest
Posts: n/a
 
      01-23-2007
On Jan 23, 9:49 am, "karunesh" <(E-Mail Removed)> wrote:
> Erik Wikström wrote:
> > On Jan 23, 8:07 am, "karunesh" <(E-Mail Removed)> wrote:
> > > why this #pragma use very extnsivly

>
> > Pragma directives are implementation specific and ignored on
> > implementations that don't understand them. Some uses that I know of is
> > in MS VC++ uses them instead of include-guards. I seem to recall that
> > they can be used on some platforms to specify alignment of members of
> > classes and structs. I think OpenMP uses them to indicate parts of the
> > code that should be parallelized. Another common usage is to set
> > compiler-options that could just as well have been passed as command
> > line options.


Try to post your replys below the text you are replying to.

> Thanks for a beautiful Explation .
> as i know in inclusion gard we use
>
> #ifndef _SOME_
>
> /* Header file body */
>
> #endif
>
> and i remmber some where i read that #pragma can be use for structure
> paddsing .
> some where i also read that its also use to change in entery point of
> the programe.
>
> can you put focus on the same ..
> how this can be handle


Might be possible, but I've never seen it. But as I said it's
implementation-specific so you can't expect it to work on anything but
the one compiler and platform you tested it on (maybe even on that
specific installation). Besides I can't see any benefit of changing the
entry-point of a program, unless you are writing a library like a DLL
or something, but then you are already using implementation specific
stuff anyway.

A good rule is to avoid using pragmas unless your _really_ need them as
they might render your code unportable.

--
Erik Wikström

 
Reply With Quote
 
gaurish.panse@gmail.com
Guest
Posts: n/a
 
      01-23-2007
A deep explanation is available in MSDN help for MSVC pragmas. GCC
doesn't provide much pragmas.

 
Reply With Quote
 
Michael
Guest
Posts: n/a
 
      01-23-2007

karunesh wrote:
> Dear Erik ,
>
> Thanks for a beautiful Explation .
> as i know in inclusion gard we use
>
> #ifndef _SOME_
>
> /* Header file body */
>
> #endif


In MSVC, the same code could be written as:

#pragma once
/* Header file body */

Note that your way is portable. But the one nice thing about the
pragma approach is that it avoids the error when you cut and paste your
code to another file, and forget to rename _SOME_, then your header
files clash. (I.e., you can just put that one line, and don't have to
edit it for each header file.)

The other time I tend to use pragmas is to turn certain warnings off.
MSVC has one particularly annoying one if you do something like this:
std::map<std::string, int>
where when it instantiates templates, it winds up creating mangled
names that are really long and then gives you a warning that the names
are very long. I tend to turn that one off (although now I favor
turning it off globally across the whole project, rather than using
#pragma on a file-by-file basis). As was mentioned before,
implementation-specific stuff.

Michael

 
Reply With Quote
 
Ondra Holub
Guest
Posts: n/a
 
      01-23-2007

karunesh napsal:
> why this #pragma use very extnsivly
>
> please tell me the usses
> thaks!!
> Regards,
> Karuensh


Do not use #pragma. If you think you need it, you are 99% wrong and you
really do not need it. #pragma is great way how to create code with low
maintanability.

One nice example are headers of standard C++ library in Microsoft
Visual C++ compiler. If you try simple program which uses for example
std::map and turn all warnings on, you get warnings on #pragmas, which
are disabling warnings (there is not such warning).

 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      01-23-2007
Ondra Holub wrote:
> karunesh napsal:
>
>>why this #pragma use very extnsivly
>>
>>please tell me the usses
>>thaks!!
>>Regards,
>>Karuensh

>
>
> Do not use #pragma. If you think you need it, you are 99% wrong and you
> really do not need it. #pragma is great way how to create code with low
> maintanability.
>

So you haven't worked with OpenMP or embedded environments? The latter
often have pragmas for machine specific options.

The advice is sound for portable code for a hosted environment.

--
Ian Collins.
 
Reply With Quote
 
robertwessel2@yahoo.com
Guest
Posts: n/a
 
      01-23-2007


On Jan 23, 12:15 pm, "Michael" <(E-Mail Removed)> wrote:
> karunesh wrote:
> > #endifIn MSVC, the same code could be written as:

>
> #pragma once
> /* Header file body */
>
> Note that your way is portable. But the one nice thing about the
> pragma approach is that it avoids the error when you cut and paste your
> code to another file, and forget to rename _SOME_, then your header
> files clash. (I.e., you can just put that one line, and don't have to
> edit it for each header file.)



While quite OT, the other "advantage" of MS's #pragma once is that it
prevents the entire second (and subsequent) inclusions of the header
from happening at all. So compilation speeds can potentially improve
when you have multiple inclusions of a large header.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Could not use ''; file already in use. M K ASP .Net 11 04-09-2008 11:35 AM
where to use CPLD & where to use FPGA? kulkarku@math.net VHDL 6 03-06-2006 07:27 AM
How do I know when to use the Viewstate and when to use the posted data? :-) Simon ASP .Net 1 11-09-2004 02:32 AM
Can I use XPath or something to a remote Mac or Linux box and just query an xml file, not using web services and use encyrption? jake ASP .Net 0 07-06-2004 02:16 PM
Cannot use the profile "default" because it is in use, not. please.post@yur.re.ply Firefox 1 07-04-2004 03:41 AM



Advertisments