Answer to question 4.8 from the FAQ

  • Thread starter Jean-François Lemaire
  • Start date
J

Jean-François Lemaire

Hello,

In the answer to question 4.8 I see this code (copied and pasted):

-------------------------
void f(ipp)
int **ipp;
{
static int dummy = 5;
*ipp = &dummy;
}
....

int *ip;
f(&ip);
-------------------------

I'm confused about the two first lines. Should'nt the first one be
written 'void f(**ipp)' and the second one scrapped altogether?

If not, I don't understand how the above can be legal.

JFL
 
E

Eric Sosman

Jean-François Lemaire said:
Hello,

In the answer to question 4.8 I see this code (copied and pasted):

-------------------------
void f(ipp)
int **ipp;
{
static int dummy = 5;
*ipp = &dummy;
}
...

int *ip;
f(&ip);

ITYM `void f(int **ipp)'.
If not, I don't understand how the above can be legal.

Question 11.3 has a useful hint, and 11.4 is worth
a look, too.
 
J

Jean-François Lemaire

ITYM `void f(int **ipp)'.

IID (Indeed I Did).
Question 11.3 has a useful hint, and 11.4 is worth
a look, too.

OK, I understand now. I'm not used to reading the old style syntax and
would have never thought it was simply that.

Thanks for pointing me in the right direction.

JFL
 
K

Keith Thompson

Jean-Francois Lemaire said:
In the answer to question 4.8 I see this code (copied and pasted):

-------------------------
void f(ipp)
int **ipp;
{
static int dummy = 5;
*ipp = &dummy;
}
[...]

That's an old-style function definition; it predates the ANSI
standard, but it's still permitted, even in C99.

What I don't know is why the FAQ still uses it here. I see no good
reason not to use a prototype. Probably it's just an oversight. I've
sent e-mail to Steve Summit.

(Sorry about mangling your name; this environment isn't handling
non-ASCII characters very well.)
 
J

Jean-François Lemaire

Jean-Francois Lemaire said:
In the answer to question 4.8 I see this code (copied and pasted):

-------------------------
void f(ipp)
int **ipp;
{
static int dummy = 5;
*ipp = &dummy;
}
[...]

That's an old-style function definition; it predates the ANSI
standard, but it's still permitted, even in C99.

What I don't know is why the FAQ still uses it here. I see no good
reason not to use a prototype. Probably it's just an oversight. I've
sent e-mail to Steve Summit.

Yes, this can be confusing for new users of the language, the intended
audience of the FAQ, who are less likely to have encountered such a
function definition. At least it was confusing for me.
(Sorry about mangling your name; this environment isn't handling
non-ASCII characters very well.)

No excuse needed, I can assure you.

JFL
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top