 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
John Nagle Guest
|
Posted: Wed Dec 06, 2006 6:38 am Post subject: Limits of declaration syntax |
|
|
This is valid, but requires typedefs.
Can this return type be written in a single statement?
Or does that exceed the capabilities of the declaration syntax?
typedef char array3[3];
typedef array3& array3ref;
array3ref foo();
John Nagle
Animats
---
[ 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.comeaucomputing.com/csc/faq.html ] |
|
| Back to top |
|
 |
Greg Herlihy Guest
|
Posted: Wed Dec 06, 2006 3:38 pm Post subject: Re: Limits of declaration syntax |
|
|
John Nagle wrote:
| Quote: | This is valid, but requires typedefs.
Can this return type be written in a single statement?
Or does that exceed the capabilities of the declaration syntax?
typedef char array3[3];
typedef array3& array3ref;
array3ref foo();
|
I'm not sure whether a valid declaration ever requires a typedef -
though they can certainly help. I believe in this case the equivalent
declaration without resorting to a typedef would be:
char ( &foo() )[3];
Greg
---
[ 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.comeaucomputing.com/csc/faq.html ] |
|
| Back to top |
|
 |
t.y.c. Guest
|
Posted: Wed Dec 06, 2006 3:38 pm Post subject: Re: Limits of declaration syntax |
|
|
On Dec 6, 2:38 pm, John Nagle <n...@animats.com> wrote:
| Quote: | This is valid, but requires typedefs.
Can this return type be written in a single statement?
Or does that exceed the capabilities of the declaration syntax?
typedef char array3[3];
typedef array3& array3ref;
array3ref foo();
You can do it as follow: |
typedef char (&array3ref)[3];
But I don't think this type is useful ^_^ , array3& is enough
---
[ 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.comeaucomputing.com/csc/faq.html ] |
|
| Back to top |
|
 |
Andrew Koenig Guest
|
Posted: Wed Dec 06, 2006 3:39 pm Post subject: Re: Limits of declaration syntax |
|
|
"John Nagle" <nagle (AT) animats (DOT) com> wrote in message
news:pvpdh.19462$9v5.10796 (AT) newssvr29 (DOT) news.prodigy.net...
| Quote: | This is valid, but requires typedefs.
Can this return type be written in a single statement?
Or does that exceed the capabilities of the declaration syntax?
typedef char array3[3];
typedef array3& array3ref;
array3ref foo();
|
charr (&foo())[3];
---
[ 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.comeaucomputing.com/csc/faq.html ] |
|
| Back to top |
|
 |
James Dennett Guest
|
Posted: Wed Dec 06, 2006 4:06 pm Post subject: Re: Limits of declaration syntax |
|
|
John Nagle wrote:
| Quote: | This is valid, but requires typedefs.
Can this return type be written in a single statement?
Or does that exceed the capabilities of the declaration syntax?
typedef char array3[3];
typedef array3& array3ref;
array3ref foo();
|
Looks nothing special to me, beyond the usual pathological
nature of C++ declaration syntax:
char array[3];
char (&foo())[3]
{
return array;
}
This compiles for me with Comeau C++ 4.3.3, and with g++
3.3. (Of course it's clearer with suitable typedefs, and
this is rather an odd case to want anyway, but the syntax
allows it.)
-- 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.comeaucomputing.com/csc/faq.html ] |
|
| Back to top |
|
 |
James Kanze Guest
|
Posted: Wed Dec 06, 2006 4:08 pm Post subject: Re: Limits of declaration syntax |
|
|
John Nagle wrote:
| Quote: | This is valid, but requires typedefs.
Can this return type be written in a single statement?
Or does that exceed the capabilities of the declaration syntax?
typedef char array3[3];
typedef array3& array3ref;
array3ref foo();
|
char (&foo())[ 3 ] ;
As usual, you start with what you want to declare: "foo". It's
a function, so "foo()", which returns a reference "&foo()" to
an array "&foo()[3]"---but the precedance is wrong, so we need
parentheses "(&foo())[3]". And finally, char.
I'll admit that it looks a little strange as a definition:
char (&foo())[ 3 ]
{
// ...
}
Make it a const member function, and have the array contain
pointers to member functions, and the syntax can become
downright difficult. Something like the following (which
declares a function taking an int as a parameter, and not a
double):
void (Bar::*(&Bar::foo( int i ) const)[ 3 ])( double d )
(To read, at least. Curiously, I find it easier to write the
declarations. But what good is it to write such declarations,
if you don't understand what they mean when you later read the
code?)
--
James Kanze (GABI Software) email:james.kanze (AT) gmail (DOT) com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
---
[ 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.comeaucomputing.com/csc/faq.html ] |
|
| Back to top |
|
 |
Kristof Zelechovski Guest
|
Posted: Mon Dec 11, 2006 1:18 am Post subject: Re: Limits of declaration syntax |
|
|
Uzytkownik "Greg Herlihy" <greghe (AT) pacbell (DOT) net> napisal w wiadomosci
news:1165409202.575999.37530 (AT) n67g2000cwd (DOT) googlegroups.com...
| Quote: |
John Nagle wrote:
This is valid, but requires typedefs.
Can this return type be written in a single statement?
Or does that exceed the capabilities of the declaration syntax?
typedef char array3[3];
typedef array3& array3ref;
array3ref foo();
I'm not sure whether a valid declaration ever requires a typedef -
|
operator char (&(void))[02], anyone?
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.comeaucomputing.com/csc/faq.html ] |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|