By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,148 Members | 1,339 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,148 IT Pros & Developers. It's quick & easy.

complex declarations

P: n/a
Hi,
recently I attended a test on C where I was asked to declare the
following declarations in one line.

void ** ( *p )(int *, char *);
int *a;

how should i do this shall i use typedef for it.

Thanks,

Jul 3 '06 #1
Share this Question
Share on Google+
12 Replies


P: n/a
no********@gmail.com wrote:
Hi,
recently I attended a test on C where I was asked to declare the
following declarations in one line.

void ** ( *p )(int *, char *);
int *a;
Why? The question doesn't make sense.

--
Ian Collins.
Jul 3 '06 #2

P: n/a

no********@gmail.com wrote:
Hi,
recently I attended a test on C where I was asked to declare the
following declarations in one line.

void ** ( *p )(int *, char *);
int *a;

how should i do this shall i use typedef for it.
It not clear what you were asked to do. Write out the declarations in
English or concactenate them into a single line...

Maybe you can clarify further?

Jul 3 '06 #3

P: n/a
for example
we can declare two variables as:
int i;
int j;

and also we can combine them to form a single line of declaration
int i,j;

in the similar way.
santosh wrote:
no********@gmail.com wrote:
Hi,
recently I attended a test on C where I was asked to declare the
following declarations in one line.

void ** ( *p )(int *, char *);
int *a;

how should i do this shall i use typedef for it.

It not clear what you were asked to do. Write out the declarations in
English or concactenate them into a single line...

Maybe you can clarify further?
Jul 3 '06 #4

P: n/a
it was a question.
may be they wanted to know my pointer knowledge.
Ian Collins wrote:
no********@gmail.com wrote:
Hi,
recently I attended a test on C where I was asked to declare the
following declarations in one line.

void ** ( *p )(int *, char *);
int *a;
Why? The question doesn't make sense.

--
Ian Collins.
Jul 3 '06 #5

P: n/a
void ** ( *p )(int *, char *); int *a;

at least, gcc allows you to do this, but it sounds to me that you have
got the question mixed up/misinterpreted. Surely no examiner would ask
such a stupid question...

Jul 3 '06 #6

P: n/a
void ** ( *p )(int *, char *); int *a;

at least, gcc allows you to do this, but it sounds to me that you have
got the question mixed up/misinterpreted. Surely no examiner would ask
such a stupid question...

Jul 3 '06 #7

P: n/a
I worked out the answer
we can write the declaration as
void **(*p)(int *,char *), *a;

now later when we use a we can typecast it to int *.
It will work without typecasting as well.
I tried it out. it works.

Thanks

no********@gmail.com wrote:
it was a question.
may be they wanted to know my pointer knowledge.
Ian Collins wrote:
no********@gmail.com wrote:
Hi,
>
>
recently I attended a test on C where I was asked to declare the
following declarations in one line.
>
void ** ( *p )(int *, char *);
int *a;
>
Why? The question doesn't make sense.

--
Ian Collins.
Jul 3 '06 #8

P: n/a
no********@gmail.com wrote:

Please don't top post.
santosh wrote:
>>no********@gmail.com wrote:
>>>Hi,
recently I attended a test on C where I was asked to declare the
following declarations in one line.

void ** ( *p )(int *, char *);
int *a;

how should i do this shall i use typedef for it.

It not clear what you were asked to do. Write out the declarations in
English or concactenate them into a single line...

Maybe you can clarify further?

for example
we can declare two variables as:
int i;
int j;

and also we can combine them to form a single line of declaration
int i,j;
Which many (including me) consider very bad style.

I still don't see how this relates to the question, why would you want
to put a function pointer and an int pointer declaration on one line?

--
Ian Collins.
Jul 3 '06 #9

P: n/a
no********@gmail.com wrote:
Hi,
recently I attended a test on C where I was asked to declare the
following declarations in one line.

void ** ( *p )(int *, char *);
int *a;

how should i do this shall i use typedef for it.
void ** ( *p )(int *, char *); int *a;

Jul 3 '06 #10

P: n/a
no********@gmail.com wrote:
santosh wrote:
no********@gmail.com wrote:
>
recently I attended a test on C where I was asked to declare the
following declarations in one line.
>
void ** ( *p )(int *, char *);
int *a;
>
how should i do this shall i use typedef for it.
It not clear what you were asked to do. Write out the declarations in
English or concactenate them into a single line...

Maybe you can clarify further?

for example
we can declare two variables as:
int i;
int j;

and also we can combine them to form a single line of declaration
int i,j;

in the similar way.
If what you say is correct, then it's certainly a stupid question!

Just combine them into a line like this:

void ** (*p)(int *, char *); int *a;

Jul 3 '06 #11

P: n/a
no********@gmail.com wrote:
recently I attended a test on C where I was asked to declare the
following declarations in one line.

void ** ( *p )(int *, char *);
int *a;

I worked out the answer
we can write the declaration as
void **(*p)(int *,char *), *a;
You changed the declaration. You were asked to declare a as pointer to
int, according to your own original post, and your solution declares it
as pointer to void.
now later when we use a we can typecast it to int *.
It will work without typecasting as well.
I tried it out. it works.
No, it doesn't. The original declaration allows you to write *a = 0;.
Your modified declaration does not. It's possible that what you wrote
is the intended solution, but if that's the case, the question was
simply plain wrong.

Jul 3 '06 #12

P: n/a
no********@gmail.com wrote:
I worked out the answer
we can write the declaration as
void **(*p)(int *,char *), *a;

now later when we use a we can typecast it to int *.
It will work without typecasting as well.
I tried it out. it works.
This is so gobsmackingly awful an idea that I urge you
to forget it immediately and read K&R2.

If that's what the people who were testing you /wanted/
my advice would be to run away, very fast, very far, very
soon.

--
Chris "very writhing in coils" Dollin
"Never ask that question!" Ambassador Kosh, /Babylon 5/

Jul 3 '06 #13

This discussion thread is closed

Replies have been disabled for this discussion.