question about declaration - pointers

J

jeniffer

What does the following declare?
char*(*(*x)(void))[];

How to judge these type of questions? I am confused :(
 
J

Joachim Schmitz

jeniffer said:
What does the following declare?
char*(*(*x)(void))[];

How to judge these type of questions? I am confused :(
WiINcdecl says:
declare x as pointer to function (void) returning pointer to array of
pointer to char

In General you'd have to work this from the inside (the inner most part,
here thr x) to the outside, alternatiting left and right

*x is a pointer
() to a function
(void) that takes no arguments
* and returns a pointer
[] to an array
char * of pointers to char

Bye, Jojo
 
A

army1987

jeniffer said:
What does the following declare?
char*(*(*x)(void))[];
A pointer to a function taking no arguments, and returning a pointer to an
array of unspecified length of pointers to char.
How to judge these type of questions? I am confused :(
See http://www.c-faq.com/ question 1.21, and remind to whoever wrote that
stuff that typedef exists. :)
 
R

Richard Heathfield

jeniffer said:
What does the following declare?
char*(*(*x)(void))[];

Others have already answered this part of your question.
How to judge these type of questions? I am confused :(

Judge these types of questions harshly. The question you show is
practically meaningless, because it tests a skill that is only needed when
deconstructing and rewriting badly-written code.
 
J

jeniffer

jeniffer said:
char*(*(*x)(void))[];
How to judge these type of questions? I am confused :(

WiINcdecl says:
declare x as pointer to function (void) returning pointer to array of
pointer to char

In General you'd have to work this from the inside (the inner most part,
here thr x) to the outside, alternatiting left and right

*x is a pointer
() to a function
(void) that takes no arguments
* and returns a pointer
[] to an array
char * of pointers to char

Bye, Jojo


Thanks a lot for the answer!
 
V

vippstar

jeniffer said:
What does the following declare?
char*(*(*x)(void))[];

Others have already answered this part of your question.
How to judge these type of questions? I am confused :(

Judge these types of questions harshly. The question you show is
practically meaningless, because it tests a skill that is only needed when
deconstructing and rewriting badly-written code.

What if you are writing a C compiler or something similar?
Shall the compiler error because the programmer used a 'bad' data
type?
 
R

Richard Heathfield

(e-mail address removed) said:
jeniffer said:
What does the following declare?
char*(*(*x)(void))[];

Others have already answered this part of your question.
How to judge these type of questions? I am confused :(

Judge these types of questions harshly. The question you show is
practically meaningless, because it tests a skill that is only needed
when deconstructing and rewriting badly-written code.

What if you are writing a C compiler or something similar?

What if you are? :)
Shall the compiler error because the programmer used a 'bad' data
type?

The compiler should diagnose syntax errors and constraint violations, but
the above is not either of those. It follows the rules of the grammar, and
so the compiler writer will be able to deal with it simply by implementing
the grammar, which is a darn sight easier than decoding the above. (But
yes, okay, you're right - a compiler writer ought to be able to decode
such expressions by hand, even if it's only for testing purposes.)
 
B

Ben Pfaff

jeniffer said:
What does the following declare?
char*(*(*x)(void))[];

Others have already answered this part of your question.
How to judge these type of questions? I am confused :(

Judge these types of questions harshly. The question you show is
practically meaningless, because it tests a skill that is only needed when
deconstructing and rewriting badly-written code.

What if you are writing a C compiler or something similar?

I surely would not mind if the C compiler diagnosed the above
similar to:

foo.c:6: warning: complicated type declarations are difficult to understand
 
D

Dann Corbit

jeniffer said:
What does the following declare?
char*(*(*x)(void))[];

How to judge these type of questions? I am confused :(

E:\>cdecl
Type `help' or `?' for help
cdecl> explain char*(*(*x)(void))[];
declare x as pointer to function (void) returning pointer to array of
pointer to char
cdecl>

Look on the net for cdecl.zip

There are other distributions as well (e.g. in BSD code base)
 
R

Richard Heathfield

Dann Corbit said:

Look on the net for cdecl.zip

I have done so. I even found it. The zip file was corrupted...
There are other distributions as well (e.g. in BSD code base)

....so I found a version written by Graham Ross, supposedly converted to
ANSI C by David Wolverton, which didn't compile. Once I got it to compile
(by removing features), it didn't link. Once I got it to link (by removing
more features), it didn't run (segfaulted straight away).

The cdecl functionality is a perfectly good example of code that *could* be
written in solid, clc-conforming ISO C code. And who knows? Perhaps it has
been. If so, where may it be found? And if not, well, I'll add it to my
to-do list.
 
U

user923005

Dann Corbit said:



I have done so. I even found it. The zip file was corrupted...


...so I found a version written by Graham Ross, supposedly converted to
ANSI C by David Wolverton, which didn't compile. Once I got it to compile
(by removing features), it didn't link. Once I got it to link (by removing
more features), it didn't run (segfaulted straight away).

The cdecl functionality is a perfectly good example of code that *could* be
written in solid, clc-conforming ISO C code. And who knows? Perhaps it has
been. If so, where may it be found? And if not, well, I'll add it to my
to-do list.

The one that I have builds fine with MINGW, but not with ANSI/ISO C
because it uses POSIX features.
 

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
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top