Is this a legal function type?

J

Jonathan Turkanis

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?

Jonathan
 
P

Pete Becker

Jonathan said:
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.
 
J

Jonathan Turkanis

Pete Becker said:
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 ];
}
 
J

Jonathan Turkanis

// Array has size 0 iff types are the same. :)
char c[ is_same<int(char(*)(long)), int(char(long))>::value ];

Should be 'iff types are not the same'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,163
Messages
2,570,897
Members
47,434
Latest member
TobiasLoan

Latest Threads

Top