Hello all.
I recently came across a function declaration as :
char(*(*x())[ ])();
This was not in some code but it was in a C questions thread on some
group.
I tried to decipher what it returns but couldn't make complete sense
out of it. Can someone please explain what this function is supposed
to return and expand it step by step.
Thanks,
Harsha 13 1979
Sri Harsha Dandibhotla <ha********@gma il.comwrites:
>Hello all. I recently came across a function declaration as : char(*(*x())[ ])(); This was not in some code but it was in a C questions thread on some group. I tried to decipher what it returns but couldn't make complete sense out of it. Can someone please explain what this function is supposed to return and expand it step by step.
Hello Harsha,
You may like to seek out a helpful tool named 'cdecl',
which is available as C source and, thus, runs on a variety of platforms.
For your example it gives the answer:
SHELL$ cdecl
Type `help' or `?' for help
cdecl explain char(*(*x())[ ])()
declare x as function returning pointer to array of pointer to function returning char
--
Chris.
Sri Harsha Dandibhotla said:
Hello all.
I recently came across a function declaration as :
char(*(*x())[ ])();
This was not in some code but it was in a C questions thread on some
group.
I tried to decipher what it returns but couldn't make complete sense
out of it. Can someone please explain what this function is supposed
to return and expand it step by step.
Start with x, the identifier.
Look immediately right. Is it a [ ? No.
Is it a (? Yes: x( Keep reading until you hit the closing parenthesis.
char(*(* )[ ])()
x()
"x is a function returning"
Now read left. Is it a ( ? No.
Is it a *, const, or volatile? If so, keep reading left till it isn't:
char(*( )[ ])()
*x()
"x is a function returning a pointer to"
Is the next thing on the left a (? Yes, and this is a grouping thing, so we
can just balance out parentheses, without adding anything:
char(* [ ])()
(*x())
"x is a function returning a pointer to"
Look right. Is the thing on the right a [? Yes, it is.
char(* )()
(*x())[ ]
"x is a function returning a pointer to an array of"
Is the thing to the right a (? No.
Is the thing to the left a (? No.
Is the thing to the left a const, volatile, or *? Yes. Keep reading left until
it isn't.
char( )()
*(*x())[ ]
"x is a function returning a pointer to an array of pointer to"
Is the thing to the left a (? Yes. Read up to the ).
char ()
(*(*x())[ ])
"x is a function returning a pointer to an array of pointer to"
Is the thing to the right a [ ? No.
Is the thing to the right a (? Yes. Read up to the matching )...
char
(*(*x())[ ])()
"x is a function returning a pointer to an array of pointer to function
returning"
Is the thing to the left a (? No.
Is it const/volatile/*? No.
Whatever's left, tack on the end:
char (*(*x())[ ])()
"x is a function returning a pointer to an array of pointer to function
returning char"
--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
On Jun 16, 11:36 am, Chris McDonald <ch...@csse.uwa .edu.auwrote:
Sri Harsha Dandibhotla <harsha....@gma il.comwrites:
Hello all.
I recently came across a function declaration as :
char(*(*x())[ ])();
This was not in some code but it was in a C questions thread on some
group.
I tried to decipher what it returns but couldn't make complete sense
out of it. Can someone please explain what this function is supposed
to return and expand it step by step.
Hello Harsha,
You may like to seek out a helpful tool named 'cdecl',
which is available as C source and, thus, runs on a variety of platforms.
For your example it gives the answer:
SHELL$ cdecl
Type `help' or `?' for help
cdecl explain char(*(*x())[ ])()
declare x as function returning pointer to array of pointer to function returning char
Thank you.
But, the tool gives the final translation, doesn't it.
Is there any other tool or is there a command line option by which it
outputs the translation as it parses?
Example: Mr.Heathfield's translation(alt hough not as detailed.)
On Jun 16, 10:04 am, Sri Harsha Dandibhotla <harsha....@gma il.com>
wrote:
On Jun 16, 11:36 am, Chris McDonald <ch...@csse.uwa .edu.auwrote:
Sri Harsha Dandibhotla <harsha....@gma il.comwrites:
>Hello all.
>I recently came across a function declaration as :
>char(*(*x())[ ])();
>This was not in some code but it was in a C questions thread on some
>group.
>I tried to decipher what it returns but couldn't make complete sense
>out of it. Can someone please explain what this function is supposed
>to return and expand it step by step.
Hello Harsha,
You may like to seek out a helpful tool named 'cdecl',
which is available as C source and, thus, runs on a variety of platforms.
For your example it gives the answer:
SHELL$ cdecl
Type `help' or `?' for help
cdecl explain char(*(*x())[ ])()
declare x as function returning pointer to array of pointer to function returning char
Thank you.
But, the tool gives the final translation, doesn't it.
Is there any other tool or is there a command line option by which it
outputs the translation as it parses?
Example: Mr.Heathfield's translation(alt hough not as detailed.)
I think it's best to avoid such tools and instead learning to read the
types as Mr Heathfield has demonstrated.
On Jun 16, 6:24 pm, Sri Harsha Dandibhotla <harsha....@gma il.com>
wrote:
Hello all.
I recently came across a function declaration as :
char(*(*x())[ ])();
(*(*x())[]) is a function returning char
therefore
(*x())[] is a pointer to function returning char
therefore
*x() is an array of pointers to function returning char
therefore
x() is a pointer to an array of pointers to function returning char
therefore
x is a function returning a pointer to an array of
pointers to function returning char
On Jun 16, 11:52 am, Richard Heathfield <r...@see.sig.i nvalidwrote:
Sri Harsha Dandibhotla said:
Hello all.
I recently came across a function declaration as :
char(*(*x())[ ])();
This was not in some code but it was in a C questions thread on some
group.
I tried to decipher what it returns but couldn't make complete sense
out of it. Can someone please explain what this function is supposed
to return and expand it step by step.
Start with x, the identifier.
Look immediately right. Is it a [ ? No.
Is it a (? Yes: x( Keep reading until you hit the closing parenthesis.
char(*(* )[ ])()
x()
"x is a function returning"
<rest snipped>
This is where I have trouble understanding. Do the parentheses on the
outside accept arguments are do those on the inside beside x.
that is, if I have to define the function, will it be
char(*(*x())[ ])(/*arguments to function*/)
{
/*function body*/
}
or will it be
char(*(*x(/*arguments to function*/))[ ])()
{
/*function body*/
}
Sri Harsha Dandibhotla said:
On Jun 16, 11:52 am, Richard Heathfield <r...@see.sig.i nvalidwrote:
>Sri Harsha Dandibhotla said:
Hello all.
I recently came across a function declaration as :
char(*(*x())[ ])();
This was not in some code but it was in a C questions thread on some
group.
I tried to decipher what it returns but couldn't make complete sense
out of it. Can someone please explain what this function is supposed
to return and expand it step by step.
Start with x, the identifier.
Look immediately right. Is it a [ ? No.
Is it a (? Yes: x( Keep reading until you hit the closing parenthesis.
char(*(* )[ ])() x() "x is a function returning"
<rest snipped>
This is where I have trouble understanding. Do the parentheses on the
outside accept arguments are do those on the inside beside x.
Either can, and neither must.
that is, if I have to define the function, will it be
char(*(*x())[ ])(/*arguments to function*/)
{
/*function body*/
}
or will it be
char(*(*x(/*arguments to function*/))[ ])()
{
/*function body*/
}
typedef is your friend.
We have a function returning a pointer to an array of pointer to function
returning char. Let's start off by defining a type, "function returning char".
I invent the convention that ft_ means "function type", and it is followed by
a printf-modifier-style abbrev representing the return type and, optionally,
something along the same lines for parameters:
typedef char ft_c(); /* ft_c is a synonym for the type "function returning
char" */
Now our declaration is reduced to:
ft_c *(*x())[];
which we might read as: "x is a function returning a pointer to an array of
pointer to ft_c", and the answer to your question now becomes clear. If we
wish for x() to take parameters, they go in the innermost parentheses, the
ones right after the identifier:
ft_c *(*x(double, char *))[];
"x is a function taking a double and a char *, which returns a pointer to an
array of pointer to ft_c"
--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Richard Heathfield <rj*@see.sig.in validwrites:
Sri Harsha Dandibhotla said:
>Hello all. I recently came across a function declaration as : char(*(*x())[ ])(); This was not in some code but it was in a C questions thread on some group. I tried to decipher what it returns but couldn't make complete sense out of it. Can someone please explain what this function is supposed to return and expand it step by step.
Start with x, the identifier.
Look immediately right. Is it a [ ? No.
Is it a (? Yes: x( Keep reading until you hit the closing parenthesis.
char(*(* )[ ])()
x()
"x is a function returning"
Now read left. Is it a ( ? No.
Is it a *, const, or volatile? If so, keep reading left till it isn't:
char(*( )[ ])()
*x()
"x is a function returning a pointer to"
Is the next thing on the left a (? Yes, and this is a grouping thing, so we
can just balance out parentheses, without adding anything:
char(* [ ])()
(*x())
"x is a function returning a pointer to"
Look right. Is the thing on the right a [? Yes, it is.
char(* )()
(*x())[ ]
"x is a function returning a pointer to an array of"
Is the thing to the right a (? No.
Is the thing to the left a (? No.
Is the thing to the left a const, volatile, or *? Yes. Keep reading left until
it isn't.
char( )()
*(*x())[ ]
"x is a function returning a pointer to an array of pointer to"
Is the thing to the left a (? Yes. Read up to the ).
char ()
(*(*x())[ ])
"x is a function returning a pointer to an array of pointer to"
Is the thing to the right a [ ? No.
Is the thing to the right a (? Yes. Read up to the matching )...
char
(*(*x())[ ])()
"x is a function returning a pointer to an array of pointer to function
returning"
Is the thing to the left a (? No.
Is it const/volatile/*? No.
Whatever's left, tack on the end:
char (*(*x())[ ])()
"x is a function returning a pointer to an array of pointer to function
returning char"
I must say, well explained - but highlights why I would never ask a
question like this in an interview. It's nigh on impossible to do it in
the head. Well, in my booze addled one anyway.
"Sri Harsha Dandibhotla" <ha********@gma il.comwrote in message
news:bc561c31- c2************* ************@l6 4g...l egroups.com...
Hello all.
I recently came across a function declaration as :
char(*(*x())[ ])();
This was not in some code but it was in a C questions thread on some
group.
I tried to decipher what it returns but couldn't make complete sense
out of it. Can someone please explain what this function is supposed
to return and expand it step by step.
I once proposed here a linear, left-to-right notation for C
declarations:
Your example would have come out as (using 'function' for extra
clarity):
function() * [] * function() char x
Read as "function returning pointer to array of pointer to function
returning char, x"
No complicated algorithm, you just need to be able to read.
But I don't remember there was much approval. Perhaps once somebody
does master the declarations they don't want their efforts undermined!
Aside from it being rather difficult to incorporate into C at this
stage.
Fortunately examples such as yours aren't common.
--
Bartc This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: The Master |
last post by:
Ok I went through and deleted code until I discovered the culprit. I
then went back to my original style sheet and removed the CSS
declaration that caused the floating to brake in safari 1.2. Once I
removed it, the floating worked as expected in safari, but broke it in
opera 7.5. The interesting part is the style declaration that causes
safari to brake is the declaration I had used to fix the bug in Opera
7.5 originally.
As far as I...
|
by: Rob Somers |
last post by:
Hey people,
I read a good thread on here regarding the reason why we use function
prototypes, and it answered most of my questions, but I wanted to
double check on a couple of things, as I am writing something up on
functions, and I don't like writing about things I am not sure about.
Ok, then, here we go:
I initially thought that one would only really need to use a function
|
by: Dennis Chang |
last post by:
Hi all,
I was reading about function pointers and came across something which
intrigued me.
K&R2 calls qsort (pg.119) within main as so:
qsort( (void **) lineptr, 0, nlines-1, (int (*) (void *, void*))(numeric ?
numcmp : strcmp) );
I guess what interests me is the nameless function pointer and then the
|
by: Daniel Nichols |
last post by:
I've noticed that in a C module (.c, .h file combination) that if you
create a function's definition before it is used in other functions
than a declaration is not necessary. I believe if the compiler can
find the definition of the function prior to encountering the use of
the function it will generate the prototype itself.
I don't currently use this feature, I explicitly create declarations
for all functions in a header file. However, I...
|
by: Christian Christmann |
last post by:
Hi,
in a benchmark I've found an uncommon use of a function.
This is the simplified form:
1 int foo( int f )
2 {
3 return f;
4 }
5
| |
by: svata |
last post by:
Hello there,
after some time of pondering I come to some solution which would suit
me best. Please correct, if I am wrong.
Function has two parameters. A string array, better said a pointer to
it, char *p_buf and int size.
int read_name( char *p_buf, int size) {
char *p_item_name_1;
|
by: f rom |
last post by:
----- Forwarded Message ----
From: Josiah Carlson <jcarlson@uci.edu>
To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org
Sent: Monday, December 4, 2006 10:03:28 PM
Subject: Re: 1>make_buildinfo.obj : error LNK2019: unresolved external symbol __imp__RegQueryValueExA@24 referenced in function _make_buildinfo2
Ask on python-list@python.org .
- Josiah
|
by: venkatagmail |
last post by:
I have problem understanding pass by value and pass by reference and
want to how how they are or appear in the memory:
I had to get my basics right again. I create an array and try all
possible ways of passing an array. In the following code, fun1(int
a1) - same as fun1(int* a1) - where both are of the type passed by
reference. Inside this function, another pointer a1 is created whose
address &a1 is different from that of the passed...
|
by: Redmond |
last post by:
Celerity is a powerful application for analysing C/C++ files.
* It can process millions of source code lines. It supports
standard C/C++. For each project, it shows the source files, include
files, source and include files, lexon indexes, includes, include-
by's, all macros, macros in a translation unit, all definitions,
definitions in a file, definitions in a translation unit, references
(function declarations and invocations),...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |