473,395 Members | 1,681 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Is this a legal function type?

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
Jul 22 '05 #1
3 2238
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.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Jul 22 '05 #2

"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 ];
}


Jul 22 '05 #3

"Jonathan Turkanis" <te******@kangaroologic.com> wrote in message
news:c1*************@ID-216073.news.uni-berlin.de...
// 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'
Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Chris Johnson | last post by:
Greetings all: I come across an interesting question (to me anyway) and I do not know the answer. Code/Questions follow: #include <iostream> #if 0 // uncommenting *should* make call...
1
by: Ajax Chelsea | last post by:
1,int (*f)(int a = 1);//is it legal? 2,int (*f)(int a = 1); int g(int a = 2){return 0;} f = &g;//is it legal?
33
by: Kenneth Brody | last post by:
I know that passing printf() too few arguments, or arguments of the wrong type invokes UB. However, what about passing too many arguments, if the expected arguments are of the correct type? For...
1
by: cindypwl | last post by:
I was looking at some code in the MS NG, and I saw this code listed. template <class T>class List{}; template<class T> bool MySortFunc(List<T>& list){return true;} template <class T>struct...
27
by: Erik de Castro Lopo | last post by:
Hi all, The GNU C compiler allows a void pointer to be incremented and the behaviour is equivalent to incrementing a char pointer. Is this legal C99 or is this a GNU C extention? Thanks in...
29
by: Ancient_Hacker | last post by:
A while back I had to recompile some old code, originally written by a really good programmer, but one prone to use every trick in the book, and then some. There was a statement, something like...
6
by: Dave Vandervies | last post by:
I'm writing an abstraction layer over an OS's ability to do non-blocking reads and writes on various things. The basic idea is that the caller will be able to let the I/O happen in the background,...
5
by: Spiros Bousbouras | last post by:
In the following assume that a is int and env is of type jmp_buf a = setjmp(env) ; Is it legal ? It looks reasonable but it seems to violate what is mentioned under "Environmental limits" of...
2
by: Army1987 | last post by:
Is this program legal C89? /* no headers included */ int main(void) { if (sizeof (exit(0), 0), ((void (* )(int))&exit)( (puts((const char *)"hello, world"), 0) ), 0) {
36
by: Max | last post by:
This was asked in a C test. Is the following code legal C? Is it legal in C90? C99? #define main() int main #define mainbody () { return 0; } mainbody
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.