Topic: is this preprocessor using code compliant with Std


Author: dont.spam.me@spamhate.com (Xenos)
Date: Sun, 19 Oct 2003 19:28:15 +0000 (UTC)
Raw View
""cody"" <dont.spam.me.deutronium@gmx.de> wrote in message
news:bmhpif$n7umd$1@ID-176797.news.uni-berlin.de...
> > can't some expert tell if this code is legal:
> >
> > #define AAA( i, j ) (i + j)
> > #define BBB( CCC, X, Y ) CCC( X, Y )
> >
> > void foo()
> > {
> >     int a, b, c;
> >     c = BBB( AAA, a, b );
> > }
>
>
> What should be wrong with it?
>
> --
> cody

Well,  for one thing the preprocessing should fail since AAA is "called"
without any parameters



---
[ 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, 20 Oct 2003 22:39:28 +0000 (UTC)
Raw View
"Xenos" <dont.spam.me@spamhate.com> wrote in message news:bmn1ti$73d2@cui1.lmms.lmco.com...

> ""cody"" <dont.spam.me.deutronium@gmx.de> wrote in message
> news:bmhpif$n7umd$1@ID-176797.news.uni-berlin.de...
> > > can't some expert tell if this code is legal:
> > >
> > > #define AAA( i, j ) (i + j)
> > > #define BBB( CCC, X, Y ) CCC( X, Y )
> > >
> > > void foo()
> > > {
> > >     int a, b, c;
> > >     c = BBB( AAA, a, b );
> > > }
> >
> >
> > What should be wrong with it?
> >
> > --
> > cody
>
> Well,  for one thing the preprocessing should fail since AAA is "called"
> without any parameters

But that's perfectly permissible. If you define a function macro, it is
expanded only if it occurs immediately before a left parenthesis. (At
which point it had better be followed by the appropriate number of
arguments and terminated with a right parenthesis.) Nothing wrong here.

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: kanze@gabi-soft.fr
Date: Mon, 20 Oct 2003 22:40:00 +0000 (UTC)
Raw View
dont.spam.me@spamhate.com (Xenos) wrote in message
news:<bmn1ti$73d2@cui1.lmms.lmco.com>...
> ""cody"" <dont.spam.me.deutronium@gmx.de> wrote in message
> news:bmhpif$n7umd$1@ID-176797.news.uni-berlin.de...
> > > can't some expert tell if this code is legal:

> > > #define AAA( i, j ) (i + j)
> > > #define BBB( CCC, X, Y ) CCC( X, Y )

> > > void foo()
> > > {
> > >     int a, b, c;
> > >     c = BBB( AAA, a, b );
> > > }

> > What should be wrong with it?

> Well, for one thing the preprocessing should fail since AAA is
> "called" without any parameters

Where is AAA "called" without any parameters?  AAA is a function style
macro, it is only invoked if the token immediately to the right is a
'('.  This is only the case once BBB has been expanded, and there, it
has the two parameters expected.

I agree with the preceding post -- I don't see anything that should be
wrong with it.

--
James Kanze           GABI Software        mailto:kanze@gabi-soft.fr
Conseils en informatique orient   e objet/     http://www.gabi-soft.fr
                    Beratung in objektorientierter Datenverarbeitung
11 rue de Rambouillet, 78460 Chevreuse, France, +33 (0)1 30 23 45 16

---
[ 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: dont.spam.me.deutronium@gmx.de ("cody")
Date: Thu, 16 Oct 2003 08:47:00 +0000 (UTC)
Raw View
> can't some expert tell if this code is legal:
>
> #define AAA( i, j ) (i + j)
> #define BBB( CCC, X, Y ) CCC( X, Y )
>
> void foo()
> {
>     int a, b, c;
>     c = BBB( AAA, a, b );
> }


What should be wrong with it?

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk


---
[ 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: dlagno@mail.nnov.ru (Denis Lagno)
Date: Fri, 3 Oct 2003 20:31:16 +0000 (UTC)
Raw View
Hi,

can't some expert tell if this code is legal:

#define AAA( i, j ) (i + j)
#define BBB( CCC, X, Y ) CCC( X, Y )

void foo()
{
    int a, b, c;
    c = BBB( AAA, a, b );
}

This code is admitted by several compilers and I used similar stuff
heavily.  But currently I am in doubt if it is compliant.

---
[ 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: Eric.Sosman@sun.com (Eric Sosman)
Date: Sat, 4 Oct 2003 01:45:57 +0000 (UTC)
Raw View
Denis Lagno wrote:
>
> Hi,
>
> can't some expert tell if this code is legal:
>
> #define AAA( i, j ) (i + j)
> #define BBB( CCC, X, Y ) CCC( X, Y )
>
> void foo()
> {
>     int a, b, c;
>     c = BBB( AAA, a, b );
> }
>
> This code is admitted by several compilers and I used similar stuff
> heavily.  But currently I am in doubt if it is compliant.

    As far as I can tell, it's legal C.  (Whether it's legal
C++ is for someone else to answer.)

    By the way, the comp.std.* groups are probably the wrong
place for this question.  Followups set to comp.lang.*.

--
Eric.Sosman@sun.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: dave@boost-consulting.com (David Abrahams)
Date: Sun, 5 Oct 2003 18:51:17 +0000 (UTC)
Raw View
dlagno@mail.nnov.ru (Denis Lagno) writes:

> Hi,
>
> can't some expert tell if this code is legal:
>
> #define AAA( i, j ) (i + j)
> #define BBB( CCC, X, Y ) CCC( X, Y )
>
> void foo()
> {
>     int a, b, c;
>     c = BBB( AAA, a, b );
> }
>
> This code is admitted by several compilers and I used similar stuff
> heavily.  But currently I am in doubt if it is compliant.

Passing it through Wave will tell you:

  http://www.codeproject.com/cpp/wave_preprocessor.asp

--
Dave Abrahams
Boost Consulting
www.boost-consulting.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                       ]