LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   parse error? (https://www.linuxquestions.org/questions/programming-9/parse-error-296590/)

ams 03-02-2005 01:22 AM

parse error?
 
i tried to compile these code...

/*
* Send the line out over the serial port, abort on error
*/
if( int serialSend( int r_serial_fd, char in_buf ) < 0 )
{
fprintf(stderr, "%s: error sending buffer, aborting, %s!\n", r_proc_name, sys_errlist[errno] );
Terminate(E_SERIAL_SEND);
}

return;
}


and the it create an error....

[ams@lan ex8]$ gcc deviceSim.c
deviceSim.c: In function `sendData':
deviceSim.c:327: parse error before "int"
deviceSim.c: At top level:
deviceSim.c:333: parse error before "return"

what does it means?

nikm 03-02-2005 02:04 AM

I think you are trying to use c++ syntax in a c program or you are using c compiler to compile a c++.

either change the syntax or use g++ compiler.

fleluhern 03-02-2005 03:03 AM

Hi!

You just have a tiny error in your code!!!

if( int serialSend( int r_serial_fd, char in_buf ) < 0 )


Two solutions can be found to your mistake.

First remove int, which is a type declaration, and which is THE mistake here.

if( serialSend( int r_serial_fd, char in_buf ) < 0 )


Second, if you want to cast serialSend, modify your code like that:

if( ((int)serialSend( int r_serial_fd, char in_buf )) < 0 )


I expect it could help you.


Good luck

ams 03-02-2005 04:30 AM

thank you buddy.....
i'll try them...

addy86 03-02-2005 04:48 AM

It might be helpful if you sended the complete definition of the function 'sendData()', and the declaration (header) of serialSend(). Why? Because
serialSend( int r_serial_fd, char in_buf )
wouldn't make much sense in C, since these variables are input values, but immediately after declaration, they do not contain any meaningful value.
And even in C++, this would make sense only if serialSend was declared as something like
int serialSend( int &r_serial_fd, char &in_buf );

perfect_circle 03-02-2005 04:56 AM

Re: parse error?
 
Quote:

Originally posted by ams
i tried to compile these code...

/*
* Send the line out over the serial port, abort on error
*/
if( int serialSend( int r_serial_fd, char in_buf ) < 0 )
{
fprintf(stderr, "%s: error sending buffer, aborting, %s!\n", r_proc_name, sys_errlist[errno] );
Terminate(E_SERIAL_SEND);
}

return;
}

this really does not make sense to me.
int serialSend( int r_serial_fd, char in_buf ) is a function declaration, not an execution.
if you write: if( (int) serialSend( int r_serial_fd, char in_buf ) < 0 ), this means cast the returning value of serialSend to int. If t's already returning int, no need to do that.
If you just want to check the returning value of serialSend do
if( serialSend( r_serial_fd, char in_buf ) < 0 ).
If you need to cast the values, because they are not ints do
if( (int) serialSend( (int) r_serial_fd, char in_buf ) < 0 )


All times are GMT -5. The time now is 11:12 AM.