"Pete Becker" <pe********@acm.org> wrote in message
news:40***************@acm.org...
Jonathan Turkanis wrote:
Can the syntax for function types be used within a function type
declaration as a synonym for the corresponding pointer-to-function
type?
For instance, is
int(char(long))
a valid type equivalent to
int(char(*)(long)),
or is it nonsense?
The latter. char(long) is not a pointer.
I know that char(long) is not a pointer, and that it is not a valid
parameter type. However, most (if not all) of my compilers (including
VC7.1, GCC 3.2, Comeau 4.3.3, Intel 7.1 and Codewarrior 9.2.) treat
int(char(*)(long))
and
int(char(long))
as the same type. (See sample program at end.)
For all I know, this could be an artifact of the way they parse
declarators, but I would have though that a diagnostic would be
required in this case.
Best Regards,
Jonathan
----------------------------------------------------------------------
----
template<typename T, typename U>
struct is_same { enum { value = false }; };
template<typename T>
struct is_same<T, T> { enum { value = true}; };
int main()
{
// Array has size 0 iff types are the same. :-)
char c[ is_same<int(char(*)(long)), int(char(long))>::value ];
}