Topic: What is the use of the null directive # ?


Author: "Krzysztof elechowski" <yecril@bluebottle.com>
Date: 18 May 2005 00:20:01 GMT
Raw View
U   ytkownik "Barry Margolin" <barmar@alum.mit.edu> napisa    w wiadomo   ci
news:barmar-AEE035.22095526062004@comcast.dca.giganews.com...
> In article <PDUseaDh1V3AFwzm@robinton.demon.co.uk>,
> francis@robinton.demon.co.uk (Francis Glassborow) wrote:
>
>> In article <607f883e.0406251028.5412fc80@posting.google.com>, Prateek R
>> Karandikar <kprateek88@yahoo.com> writes
>> >What is the use of the null-directive # ?
>> >
>> ><quote>
>> >   16.7 Null directive           [cpp.null]
>> >1  A preprocessing directive of the form
>> >       # new-line
>> >   has no effect.
>> ></quote>
>>
>> It allows implementors to add directives as extensions without having
>> impact on the portability of code using them.
>
> All it says is that the line:
>
> #
>
> is ignored.  How does that allow an implementor to add something like:
>
> #foobar
>
> ?
>

It is very simple.

#ifndef IT_IS_MY_COMPILER
#define foobar
#endif

If it is not my compiler, the pragma #foobar is reduced to a hash mark #.
If it is, it remains and my compiler can handle it.

The other way round
#ifdef IT_IS_MY_COMPILER
#define MY_PRAGMA #my_pragma
#else
#define MY_PRAGMA
#endif

is unacceptable because MY_PRAGMA (without the hash mark) does not suggest
it is a pragma.  Also, I wonder if MY_PRAGMA can be defined to anything that
starts with the hash mark #.

Chris


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: jdennett@acm.org (James Dennett)
Date: Thu, 19 May 2005 06:39:06 GMT
Raw View
Krzysztof =AFelechowski wrote:
> U=BFytkownik "Barry Margolin" <barmar@alum.mit.edu> napisa=B3 w wiadomo=
=B6ci=20
> news:barmar-AEE035.22095526062004@comcast.dca.giganews.com...
>=20
>>In article <PDUseaDh1V3AFwzm@robinton.demon.co.uk>,
>>francis@robinton.demon.co.uk (Francis Glassborow) wrote:
>>
>>
>>>In article <607f883e.0406251028.5412fc80@posting.google.com>, Prateek =
R
>>>Karandikar <kprateek88@yahoo.com> writes
>>>
>>>>What is the use of the null-directive # ?
>>>>
>>>><quote>
>>>>  16.7 Null directive           [cpp.null]
>>>>1  A preprocessing directive of the form
>>>>      # new-line
>>>>  has no effect.
>>>></quote>
>>>
>>>It allows implementors to add directives as extensions without having
>>>impact on the portability of code using them.
>>
>>All it says is that the line:
>>
>>#
>>
>>is ignored.  How does that allow an implementor to add something like:
>>
>>#foobar
>>
>>?
>>
>=20
>=20
> It is very simple.
>=20
> #ifndef IT_IS_MY_COMPILER
> #define foobar
> #endif
>=20
> If it is not my compiler, the pragma #foobar is reduced to a hash mark =
#.=20
> If it is, it remains and my compiler can handle it.

Except that macro expansion happens too late for that to work;
#foobar is recognized as an (invalid) preprocessor directive
before macro expansion is attempted.

-- James

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: ikosarev@online.ru ("Ivan A. Kosarev")
Date: Sun, 11 Jul 2004 02:07:15 +0000 (UTC)
Raw View
"Prateek R Karandikar" <kprateek88@yahoo.com> wrote in message
news:607f883e.0406251028.5412fc80@posting.google.com...

> What is the use of the null-directive # ?

With early C compilers the null-directive at the beginning of a source file
was informing about the source file should be preprocessed before further
compilation.

--
Ivan


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: kprateek88@yahoo.com (Prateek R Karandikar)
Date: Sat, 26 Jun 2004 07:04:06 +0000 (UTC)
Raw View
What is the use of the null-directive # ?

<quote>
   16.7 Null directive           [cpp.null]
1  A preprocessing directive of the form
       # new-line
   has no effect.
</quote>

--                                    --
Abstraction is selective ignorance.
-Andrew Koenig
--                                    --

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: francis@robinton.demon.co.uk (Francis Glassborow)
Date: Sat, 26 Jun 2004 18:19:15 +0000 (UTC)
Raw View
In article <607f883e.0406251028.5412fc80@posting.google.com>, Prateek R
Karandikar <kprateek88@yahoo.com> writes
>What is the use of the null-directive # ?
>
><quote>
>   16.7 Null directive           [cpp.null]
>1  A preprocessing directive of the form
>       # new-line
>   has no effect.
></quote>

It allows implementors to add directives as extensions without having
impact on the portability of code using them.


--
Francis Glassborow      ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: barmar@alum.mit.edu (Barry Margolin)
Date: Sun, 27 Jun 2004 05:48:16 +0000 (UTC)
Raw View
In article <PDUseaDh1V3AFwzm@robinton.demon.co.uk>,
 francis@robinton.demon.co.uk (Francis Glassborow) wrote:

> In article <607f883e.0406251028.5412fc80@posting.google.com>, Prateek R
> Karandikar <kprateek88@yahoo.com> writes
> >What is the use of the null-directive # ?
> >
> ><quote>
> >   16.7 Null directive           [cpp.null]
> >1  A preprocessing directive of the form
> >       # new-line
> >   has no effect.
> ></quote>
>
> It allows implementors to add directives as extensions without having
> impact on the portability of code using them.

All it says is that the line:

#

is ignored.  How does that allow an implementor to add something like:

#foobar

?

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: usenet@disemia.com (edA-qa mort-ora-y)
Date: Sun, 27 Jun 2004 07:40:50 +0000 (UTC)
Raw View
Prateek R Karandikar wrote:
> What is the use of the null-directive # ?

For continuinity I suppose, so you can put blank lines between your
directives but still see that it is all one-preprocessing chunk.

#if defined( VAR_A )
# if defined( VAR_B )
#  define VAR_C
#  define VAR_D
# endif
#
#elif defined( VAR_B )
#
#
#endif

--
edA-qa mort-ora-y (Producer)
Trostlos Records <http://trostlos.org/>

"What suffering would man know if not for his own?"

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: francis@robinton.demon.co.uk (Francis Glassborow)
Date: Sun, 27 Jun 2004 22:14:54 +0000 (UTC)
Raw View
In article <barmar-AEE035.22095526062004@comcast.dca.giganews.com>,
Barry Margolin <barmar@alum.mit.edu> writes
>In article <PDUseaDh1V3AFwzm@robinton.demon.co.uk>,
> francis@robinton.demon.co.uk (Francis Glassborow) wrote:
>
>> In article <607f883e.0406251028.5412fc80@posting.google.com>, Prateek R
>> Karandikar <kprateek88@yahoo.com> writes
>> >What is the use of the null-directive # ?
>> >
>> ><quote>
>> >   16.7 Null directive           [cpp.null]
>> >1  A preprocessing directive of the form
>> >       # new-line
>> >   has no effect.
>> ></quote>
>>
>> It allows implementors to add directives as extensions without having
>> impact on the portability of code using them.
>
>All it says is that the line:
>
>#
>
>is ignored.  How does that allow an implementor to add something like:
>
>#foobar

No it does not say that the implementor is _required_ to ignore such a
directive. What it does say is that such a directive is not cause to
abort compilation, nor does its existence require a diagnostic.

It generalises the #pragma directive so that I can write:

#packed

happy in the knowledge that any compiler that does not understand that
directive will simply ignore it.

--
Francis Glassborow      ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: kprateek88@yahoo.com (Prateek R Karandikar)
Date: Mon, 28 Jun 2004 02:21:52 +0000 (UTC)
Raw View
> >What is the use of the null-directive # ?
> >
> ><quote>
> >   16.7 Null directive           [cpp.null]
> >1  A preprocessing directive of the form
> >       # new-line
> >   has no effect.
> ></quote>
>
> It allows implementors to add directives as extensions without having
> impact on the portability of code using them.

#pragma is already there for non-standard extensions. BTW, how can a
null-directive allow implementations to add directives? The Standard
specifically says that the null directive has no effect (as opposed to
having an implementation-defined effect).

--                                    --
Abstraction is selective ignorance.
-Andrew Koenig
--                                    --

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: barmar@alum.mit.edu (Barry Margolin)
Date: Mon, 28 Jun 2004 04:02:13 +0000 (UTC)
Raw View
In article <Bt9PFkEEEq3AFwhq@robinton.demon.co.uk>,
 francis@robinton.demon.co.uk (Francis Glassborow) wrote:

> In article <barmar-AEE035.22095526062004@comcast.dca.giganews.com>,
> Barry Margolin <barmar@alum.mit.edu> writes
> >In article <PDUseaDh1V3AFwzm@robinton.demon.co.uk>,
> > francis@robinton.demon.co.uk (Francis Glassborow) wrote:
> >
> >> In article <607f883e.0406251028.5412fc80@posting.google.com>, Prateek R
> >> Karandikar <kprateek88@yahoo.com> writes
> >> >What is the use of the null-directive # ?
> >> >
> >> ><quote>
> >> >   16.7 Null directive           [cpp.null]
> >> >1  A preprocessing directive of the form
> >> >       # new-line
> >> >   has no effect.
> >> ></quote>
> >>
> >> It allows implementors to add directives as extensions without having
> >> impact on the portability of code using them.
> >
> >All it says is that the line:
> >
> >#
> >
> >is ignored.  How does that allow an implementor to add something like:
> >
> >#foobar
>
> No it does not say that the implementor is _required_ to ignore such a
> directive. What it does say is that such a directive is not cause to
> abort compilation, nor does its existence require a diagnostic.

It says it has *no* effect, it doesn't say it has an
implementation-defined effect.

>
> It generalises the #pragma directive so that I can write:
>
> #packed
>
> happy in the knowledge that any compiler that does not understand that
> directive will simply ignore it.

That's not a null directive, so I don't see how it relates to the above
section of the standard.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: pjp@dinkumware.com ("P.J. Plauger")
Date: Mon, 28 Jun 2004 05:36:01 +0000 (UTC)
Raw View
"Francis Glassborow" <francis@robinton.demon.co.uk> wrote in message
news:Bt9PFkEEEq3AFwhq@robinton.demon.co.uk...

> In article <barmar-AEE035.22095526062004@comcast.dca.giganews.com>,
> Barry Margolin <barmar@alum.mit.edu> writes
> >In article <PDUseaDh1V3AFwzm@robinton.demon.co.uk>,
> > francis@robinton.demon.co.uk (Francis Glassborow) wrote:
> >
> >> In article <607f883e.0406251028.5412fc80@posting.google.com>, Prateek R
> >> Karandikar <kprateek88@yahoo.com> writes
> >> >What is the use of the null-directive # ?
> >> >
> >> ><quote>
> >> >   16.7 Null directive           [cpp.null]
> >> >1  A preprocessing directive of the form
> >> >       # new-line
> >> >   has no effect.
> >> ></quote>
> >>
> >> It allows implementors to add directives as extensions without having
> >> impact on the portability of code using them.
> >
> >All it says is that the line:
> >
> >#
> >
> >is ignored.  How does that allow an implementor to add something like:
> >
> >#foobar
>
> No it does not say that the implementor is _required_ to ignore such a
> directive. What it does say is that such a directive is not cause to
> abort compilation, nor does its existence require a diagnostic.
>
> It generalises the #pragma directive so that I can write:
>
> #packed
>
> happy in the knowledge that any compiler that does not understand that
> directive will simply ignore it.

I have trouble reading it that way. Where in the grammar

:       # new-line

is there wiggle room to add the word 'packed', or any other
non-whitespace thingy?

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: jdennett@acm.org (James Dennett)
Date: Mon, 28 Jun 2004 05:36:13 +0000 (UTC)
Raw View
Francis Glassborow wrote:

> In article <barmar-AEE035.22095526062004@comcast.dca.giganews.com>,
> Barry Margolin <barmar@alum.mit.edu> writes
>
>> In article <PDUseaDh1V3AFwzm@robinton.demon.co.uk>,
>> francis@robinton.demon.co.uk (Francis Glassborow) wrote:
>>
>>> In article <607f883e.0406251028.5412fc80@posting.google.com>, Prateek R
>>> Karandikar <kprateek88@yahoo.com> writes
>>> >What is the use of the null-directive # ?
>>> >
>>> ><quote>
>>> >   16.7 Null directive           [cpp.null]
>>> >1  A preprocessing directive of the form
>>> >       # new-line
>>> >   has no effect.
>>> ></quote>
>>>
>>> It allows implementors to add directives as extensions without having
>>> impact on the portability of code using them.
>>
>>
>> All it says is that the line:
>>
>> #
>>
>> is ignored.  How does that allow an implementor to add something like:
>>
>> #foobar
>
>
> No it does not say that the implementor is _required_ to ignore such a
> directive.

In fact, it says *nothing* about how an implementation can
or must interpret something such as
#foobar
but rather says only that
#
has no effect in a conforming compiler

> What it does say is that such a directive is not cause to
> abort compilation, nor does its existence require a diagnostic.

You're thinking, perhaps, of the requirement that #praga foo, where
foo is not a recognized pragma name, should be a no-op.

> It generalises the #pragma directive so that I can write:
>
> #packed
>
> happy in the knowledge that any compiler that does not understand that
> directive will simply ignore it.

That generalization is explicit in the standard, and independent
of how
#
is interpreted -- an isolated # portably does nothing, but
#pragma packed
might do anything at all, if the compiler so chooses to "recognize"
the "packed" pragma.  For example, on one compiler #pragma packed
might control alignment within objects, while another could quite
legally implement it to mean that the generated *code* should be as
small as possible.

To avoid the risk of such name clashes, some considerate
implementors put their own pragmas effectively into another
namespace, and allow them to be used as
#pragma __VENDOR_X__ packed
which are unlikely to be "recognized" and interpreted
differently by another system.

-- James

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: kuyper@wizard.net (James Kuyper)
Date: Mon, 28 Jun 2004 05:36:21 +0000 (UTC)
Raw View
francis@robinton.demon.co.uk (Francis Glassborow) wrote in message news:<Bt9PFkEEEq3AFwhq@robinton.demon.co.uk>...
> In article <barmar-AEE035.22095526062004@comcast.dca.giganews.com>,
> Barry Margolin <barmar@alum.mit.edu> writes
> >In article <PDUseaDh1V3AFwzm@robinton.demon.co.uk>,
> > francis@robinton.demon.co.uk (Francis Glassborow) wrote:
> >
> >> In article <607f883e.0406251028.5412fc80@posting.google.com>, Prateek R
> >> Karandikar <kprateek88@yahoo.com> writes
> >> >What is the use of the null-directive # ?
> >> >
> >> ><quote>
> >> >   16.7 Null directive           [cpp.null]
> >> >1  A preprocessing directive of the form
> >> >       # new-line
> >> >   has no effect.
> >> ></quote>
> >>
> >> It allows implementors to add directives as extensions without having
> >> impact on the portability of code using them.
> >
> >All it says is that the line:
> >
> >#
> >
> >is ignored.  How does that allow an implementor to add something like:
> >
> >#foobar
>
> No it does not say that the implementor is _required_ to ignore such a
> directive. What it does say is that such a directive is not cause to
> abort compilation, nor does its existence require a diagnostic.

"has no effect" seems pretty clear to me.

> It generalises the #pragma directive so that I can write:
>
> #packed
>
> happy in the knowledge that any compiler that does not understand that
> directive will simply ignore it.

But what does the null directive have to do with that? Neither #foobar
nor #packed are null directives.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: Francis Glassborow <francis@robinton.demon.co.uk>
Date: 28 Jun 2004 18:55:01 GMT
Raw View
In article <2VIDc.8800$DT5.5297@nwrddc03.gnilink.net>, P.J. Plauger
<pjp@dinkumware.com> writes
>I have trouble reading it that way. Where in the grammar
>
>:       # new-line
>
>is there wiggle room to add the word 'packed', or any other
>non-whitespace thingy?

You are right. I completely misread the sub-clause. Which actually says
that an empty preprocessor directive does nothing. That may seem obvious
to some but most of us here know that such things have to be specified
else they invoke undefined behaviour.

My apologies for carelessly misreading (i.e. not noting the use of font
in the quoted text)



--
Francis Glassborow      ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: "Paul Mensonides" <leavings@comcast.net>
Date: Tue, 29 Jun 2004 16:43:45 CST
Raw View
"Francis Glassborow" <francis@robinton.demon.co.uk> wrote in message
news:X0YaTxJvHA4AFwbF@robinton.demon.co.uk...
> In article <2VIDc.8800$DT5.5297@nwrddc03.gnilink.net>, P.J. Plauger
> <pjp@dinkumware.com> writes
> >I have trouble reading it that way. Where in the grammar
> >
> >:       # new-line
> >
> >is there wiggle room to add the word 'packed', or any other
> >non-whitespace thingy?
>
> You are right. I completely misread the sub-clause. Which actually says
> that an empty preprocessor directive does nothing. That may seem obvious
> to some but most of us here know that such things have to be specified
> else they invoke undefined behaviour.
>
> My apologies for carelessly misreading (i.e. not noting the use of font
> in the quoted text)

You aren't too far off, Francis.  The C99 standard introduces another production

# non-directive

which covers any case like #packed where the name after # is not a standard
directive name.

Regards,
Paul Mensonides


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]