473,804 Members | 3,305 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

use of #Pragma

why this #pragma use very extnsivly

please tell me the usses
thaks!!
Regards,
Karuensh

Jan 23 '07 #1
8 2241
On Jan 23, 8:07 am, "karunesh" <karunesh....@g mail.comwrote:
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

Jan 23 '07 #2
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" <karunesh....@g mail.comwrote:
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
Jan 23 '07 #3
On Jan 23, 9:49 am, "karunesh" <karunesh....@g mail.comwrote:
Erik Wikström wrote:
On Jan 23, 8:07 am, "karunesh" <karunesh....@g mail.comwrote:
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

Jan 23 '07 #4
A deep explanation is available in MSDN help for MSVC pragmas. GCC
doesn't provide much pragmas.

Jan 23 '07 #5

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::s tring, 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

Jan 23 '07 #6

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

Jan 23 '07 #7
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.
Jan 23 '07 #8


On Jan 23, 12:15 pm, "Michael" <mchlg...@aol.c omwrote:
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.

Jan 23 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
2666
by: Steven T. Hatton | last post by:
Stroustrup says this: http://www.research.att.com/~bs/bs_faq2.html#macro "So, what's wrong with using macros?" "And yes, I do know that there are things known as macros that doesn't suffer the problems of C/C++ preprocessor macros. However, I have no
6
3971
by: Shri | last post by:
Can anybody tell me where i can find a detailed document on #pragma .... --shri
1
3087
by: Gustavo L. Fabro | last post by:
Greetings! Going directly to the point: myclass.h: //-------------------------------------- #pragma managed //Forward declaration
11
2872
by: ramu | last post by:
HI, Can anyone tell me about pragma? And can u give an example of how to use it?
15
3763
by: muttaa | last post by:
Hello all, I'm a beginner in C...May i like to know the difference between a #pragma and a #define.... Also,yet i'm unclear what a pragma is all about as i can find topics on it only in high-standard books...
8
7884
by: rwen2012 | last post by:
Hi, guys, I am confused with the preprocessor instruction #pragma. What does the #pragma mean? and what does this mean as follow? ==================== #pragma intterupt Timer ====================
5
3611
by: venkat | last post by:
Hi, I have come across the a pragma definition " #pragma switch direct ". I don't know any thing about pragma's. Even i when i search through google not getting exact information. what does pragma does?. what the statment "#pragma switch direct" does?. Thanks, Venkat.
26
3832
by: Rick | last post by:
I'm told that "#pragma once" has made it into the ISO standard for either C or C++. I can't find any reference to that anywhere. If it's true, do any of you have a reference I can use? Thanks...
2
3922
by: aleemakhtar1 | last post by:
wat is use of pragma directive in embedded sys ??
0
10696
debasisdas
by: debasisdas | last post by:
PRAGMA:-Signifies that the statement is a pragma (compiler directive). Pragmas are processed at compile time, not at run time. They pass information to the compiler. A pragma is an instruction to the Oracle compiler that tells it to do something. In this case you are telling Oracle to associate an error that you choose to a variable that you choose. This pragma must go in the declarative section of your block. Types of PRAGMA...
0
9587
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10588
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10324
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9161
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5527
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5662
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3827
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2998
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.