Parser

B

Bill Cunningham

In comp.programming I asked for advice for writing a parser. The code
someone showed me wouldn't compile. I don't know what's wrong. I just want
to write the simpliest of parsers.

int parser(FILE *in,FILE *out);

int main(void){
parser(stdin,stdout);
return0;}

Won't compile. My guess is maybe this should be written

parser(&stdin,&stdout);

But that's my opinion.

Bill
 
J

Joona I Palaste

Bill Cunningham said:
In comp.programming I asked for advice for writing a parser. The code
someone showed me wouldn't compile. I don't know what's wrong. I just want
to write the simpliest of parsers.
int parser(FILE *in,FILE *out);
int main(void){
parser(stdin,stdout);
return0;}
Won't compile. My guess is maybe this should be written

But that's my opinion.

Your opinion is wrong. stdin and stdout are of type FILE *, not of
type FILE. The reason it won't compile is the same as in your
previous post - the function parser() isn't defined anywhere, just
declared.

--
/-- Joona Palaste ([email protected]) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Remember: There are only three kinds of people - those who can count and those
who can't."
- Vampyra
 
M

Mike Wahler

Joona I Palaste said:
Your opinion is wrong. stdin and stdout are of type FILE *, not of
type FILE. The reason it won't compile is the same as in your
previous post - the function parser() isn't defined anywhere, just
declared.

That won't stop a compile (but the missing #include <stdio.h>
as well as the syntax error in the 'return' statement will.)
The missing definition will prevent successful linking
though.

-Mike
 
M

Martin Ambuhl

Bill said:
In comp.programming I asked for advice for writing a parser. The code
someone showed me wouldn't compile. I don't know what's wrong. I just want
to write the simpliest of parsers.

int parser(FILE *in,FILE *out);

int main(void){
parser(stdin,stdout);
return0;}

Won't compile. My guess is maybe this should be written

parser(&stdin,&stdout);

But that's my opinion.

And it's a bad one. The following should compile without diagnostics:

#include <stdio.h>

int parser(FILE * in, FILE * out);

int main(void)
{
parser(stdin, stdout);
return 0;
}

int parser(FILE * in, FILE * out)
{
(void) in; /* noops here to quiet */
(void) out; /* 'unused parameter' warnings. */
return 0;
}
 
B

Bill Cunningham

int parser(FILE * in, FILE * out)
{
(void) in; /* noops here to quiet */
(void) out; /* 'unused parameter' warnings. */
return 0;
}
What do the voids in parenthesis mean? Are they casts? This NG always
makes me feel dumb.

Bill
 
J

Julien Oster

Hello Bill,
What do the voids in parenthesis mean? Are they casts? This NG always
makes me feel dumb.

Yes! It's a cast. A cast to void seems pretty useless, especially in
this case where the casted value isn't even used, but it's actually
quite useful here to remove the warning.

Julien
 

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
474,141
Messages
2,570,817
Members
47,362
Latest member
ChandaWagn

Latest Threads

Top