473,396 Members | 2,108 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

unknown directive

What is #pragma used for?
Nov 14 '05 #1
13 2423
DevarajA wrote:
What is #pragma used for?


compiler specific compilation instructions.

#pragma once

is fairly common and replaces header guarding (#ifdef...#endif)

check the compiler documentation for specific pragmas that it supports.
--
Peter MacMillan
e-mail/msn: pe***@writeopen.com
icq: 1-874-927

GCS/IT/L d-(-)>-pu s():(-) a- C+++(++++)>$ UL>$ P++ L+ E-(-) W++(+++)>$
N o w++>$ O !M- V PS PE Y+ t++ 5 X R* tv- b++(+) DI D+(++)>$ G e++ h r--
y(--)
Nov 14 '05 #2
DevarajA wrote:

What is #pragma used for?


Usually to make programs non-portable. Avoid.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
Nov 14 '05 #3
DevarajA wrote on 30/03/05 :
What is #pragma used for?


Nothing.

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

..sig under repair

Nov 14 '05 #4
"Emmanuel Delahaye" <em***@YOURBRAnoos.fr> writes:
DevarajA wrote on 30/03/05 :
What is #pragma used for?


Nothing.


Huh?

C90 6.8.6 says a #pragma directive "causes the implementation to
behave in an implementation-defined manner. Any pragma that is not
recognized by the implementation is ignored."

C99 has similar wording, and additionally defines several standard
forms:

#pragma STDC FP_CONTRACT on-off-switch
#pragma STDC FENV_ACCESS on-off-switch
#pragma STDC CX_LIMITED_RANGE on-off-switch

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #5
Keith Thompson wrote on 30/03/05 :
"Emmanuel Delahaye" <em***@YOURBRAnoos.fr> writes:
DevarajA wrote on 30/03/05 :
What is #pragma used for?
Nothing.


Huh?


T'was a kinda humour... pragmas make the code not portable
C90 6.8.6 says a #pragma directive "causes the implementation to
behave in an implementation-defined manner. Any pragma that is not
recognized by the implementation is ignored."
This is the point. Two compilers can have the same pragmas with a
different meaning. Hard to find bug...
C99 has similar wording, and additionally defines several standard
forms:

#pragma STDC FP_CONTRACT on-off-switch
#pragma STDC FENV_ACCESS on-off-switch
#pragma STDC CX_LIMITED_RANGE on-off-switch


Ok. Only this form of pragma is acceptable, hoping that no vendor has
used this form previously (there was no 'reserved pragma' in C90). The
STDC trick could work... or not...

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

"Clearly your code does not meet the original spec."
"You are sentenced to 30 lashes with a wet noodle."
-- Jerry Coffin in a.l.c.c++

Nov 14 '05 #6
"Emmanuel Delahaye" <em***@YOURBRAnoos.fr> writes:
Keith Thompson wrote on 30/03/05 :
"Emmanuel Delahaye" <em***@YOURBRAnoos.fr> writes:
DevarajA wrote on 30/03/05 :
What is #pragma used for?
Nothing.


Huh?


T'was a kinda humour... pragmas make the code not portable


Right -- and non-portable code isn't the end of the world. Sometimes
it's exactly what you need. The details, of course, are off-topic
here, but the existence of non-portable code is perfectly topical.

An implementation-specific #pragma might be protected by an #ifdef,
such as:

#ifdef __ACME_C__
#pragma ACME optimize(cleverly)
#endif

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #7
In article <ln************@nuthaus.mib.org>,
Keith Thompson <ks***@mib.org> wrote:
"Emmanuel Delahaye" <em***@YOURBRAnoos.fr> writes:
Keith Thompson wrote on 30/03/05 :
"Emmanuel Delahaye" <em***@YOURBRAnoos.fr> writes:
DevarajA wrote on 30/03/05 :
> What is #pragma used for?
Nothing.

Huh?


T'was a kinda humour... pragmas make the code not portable


Right -- and non-portable code isn't the end of the world. Sometimes
it's exactly what you need. The details, of course, are off-topic
here, but the existence of non-portable code is perfectly topical.

An implementation-specific #pragma might be protected by an #ifdef,
such as:

#ifdef __ACME_C__
#pragma ACME optimize(cleverly)
#endif


....which works fine until you try to build it on the DS9k, which #defines
every symbol starting with __ (most of them to the equivalent of
#define __RHWBVH
, which saves a lot of symbol table space) and blows up the computer
it's running on when it sees a #pragma[1].
dave

[1] The DS9k C99 compiler needed a few special cases for this one.

--
Dave Vandervies dj******@csclub.uwaterloo.ca
It's TRADITIONAL in C for MACROS to HAVE upper-case NAMES, not
PLAIN VARIABLES (IN THEMSELVES).
--Chris Dollin in comp.lang.c
Nov 14 '05 #8
dj******@csclub.uwaterloo.ca (Dave Vandervies) writes:
In article <ln************@nuthaus.mib.org>,
Keith Thompson <ks***@mib.org> wrote:

[...]
An implementation-specific #pragma might be protected by an #ifdef,
such as:

#ifdef __ACME_C__
#pragma ACME optimize(cleverly)
#endif


...which works fine until you try to build it on the DS9k, which #defines
every symbol starting with __ (most of them to the equivalent of
#define __RHWBVH
, which saves a lot of symbol table space) and blows up the computer
it's running on when it sees a #pragma[1].


Which means there's one less DS9k in the world for C programmers to
worry about.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #9
Keith Thompson wrote:
dj******@csclub.uwaterloo.ca (Dave Vandervies) writes:
Keith Thompson <ks***@mib.org> wrote: [...]
An implementation-specific #pragma might be protected by an
#ifdef, such as:

#ifdef __ACME_C__
#pragma ACME optimize(cleverly)
#endif


...which works fine until you try to build it on the DS9k, which
#defines every symbol starting with __ (most of them to the

.... snip ...
Which means there's one less DS9k in the world for C programmers
to worry about.


Even the DS9k shouldn't worry about that #ifdef, because it is
simply interogating a value from the system, not defining it.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
Nov 14 '05 #10
CBFalconer <cb********@yahoo.com> writes:
Keith Thompson wrote:
dj******@csclub.uwaterloo.ca (Dave Vandervies) writes:
Keith Thompson <ks***@mib.org> wrote:

[...]
An implementation-specific #pragma might be protected by an
#ifdef, such as:

#ifdef __ACME_C__
#pragma ACME optimize(cleverly)
#endif

...which works fine until you try to build it on the DS9k, which
#defines every symbol starting with __ (most of them to the

... snip ...

Which means there's one less DS9k in the world for C programmers
to worry about.


Even the DS9k shouldn't worry about that #ifdef, because it is
simply interogating a value from the system, not defining it.


It's not the #ifdef that's a problem, it's the #pragma.

The __ACME_C__ macro was intended by the authors of the Acme C
compiler to indicate that a C program is being compiled by their
compiler. Since any implementation is allowed to define any macros it
likes in the implementation namespace, the evil authors of the DS9k C
compiler chose (in effect) to lie to their users by defining the same
symbol. The #pragma directive is then active, and causes
implementation-defined behavior -- in this case, blowing up the
computer.

(Similarly, the C standard cannot prevent non-conforming
implementations from lying by defining __STDC__ as 1; by definition,
it can't prevent non-conforming implementations from doing
*anything*.)

Such are the risks of writing non-portable code, but I'm not going to
lose any sleep over this particular instance.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #11
Dave Vandervies <dj******@csclub.uwaterloo.ca> scribbled the following:
Dave Vandervies dj******@csclub.uwaterloo.ca
It's TRADITIONAL in C for MACROS to HAVE upper-case NAMES, not
PLAIN VARIABLES (IN THEMSELVES).
--Chris Dollin in comp.lang.c


But what if they're PLAIN VARIABLES (FOR THEMSELVES)?

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"The question of copying music from the Internet is like a two-barreled sword."
- Finnish rap artist Ezkimo
Nov 14 '05 #12
Joona I Palaste wrote:
Dave Vandervies <dj******@csclub.uwaterloo.ca> scribbled the following:
Dave Vandervies dj******@csclub.uwaterloo.ca
It's TRADITIONAL in C for MACROS to HAVE upper-case NAMES, not
PLAIN VARIABLES (IN THEMSELVES).
--Chris Dollin in comp.lang.c

But what if they're PLAIN VARIABLES (FOR THEMSELVES)?


Now you've gone and awakened Karl Malbrain.
Nov 14 '05 #13
Martin Ambuhl wrote on 03/04/05 :
Joona I Palaste wrote:
Dave Vandervies <dj******@csclub.uwaterloo.ca> scribbled the following:
Dave Vandervies dj******@csclub.uwaterloo.ca
It's TRADITIONAL in C for MACROS to HAVE upper-case NAMES, not
PLAIN VARIABLES (IN THEMSELVES).
--Chris Dollin in comp.lang.c


But what if they're PLAIN VARIABLES (FOR THEMSELVES)?


Now you've gone and awakened Karl Malbrain.


Karl "Chair" Malbrain

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

"Clearly your code does not meet the original spec."
"You are sentenced to 30 lashes with a wet noodle."
-- Jerry Coffin in a.l.c.c++

Nov 14 '05 #14

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

Similar topics

2
by: Rea | last post by:
Hi! I've searched high and low for this on the net but stil haven't found an answer. I'm trying to install both postnuke and xoops on a win2k server with php 4.3.3. and mysql installed. ...
1
by: BigMan | last post by:
Should a compiler (according to the C++ standard) issue a warning (or other kind of diagnostic message) when it encounters an unknown pragma directive?
4
by: James | last post by:
Can someone please help me with these errors? #include <iostream> #include <string> class holder { private: int vid; string vtype;
2
by: Mantorok Redgormor | last post by:
what is the purpose of the #line directive? how is it suppose to be used? I didn't see it mentioned in the faq and I can't make any sense of it from the standard. -- nethlek
5
by: Jim Heavey | last post by:
Is the Page directive only go on ".aspx" pages? I think the answer is yes, but I am not positive. I am trying to figure out why a called class can not be found and I was wondering if I should...
1
by: Benign Vanilla | last post by:
Working on an ASP.NET project recently, I was trying to put a customer control into use, and kept receiving this error: Description: An error occurred during the parsing of a resource required to...
3
by: geevaa | last post by:
Hi group, PHP Warning: Module 'readline' already loaded in Unknown on line 0 what this warning means? please help me by explaining
2
by: aleemakhtar1 | last post by:
wat is use of pragma directive in embedded sys ??
2
by: Calvin Cheng | last post by:
Hi, I am attempting to convert a bunch of .txt files into html using the docutils package. It works for most of the txt files except for the index.txt file which gives 2 errors: (1)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.