473,288 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,288 software developers and data experts.

syntax error, unexpected token ... what's causing this???

175 100+
I'm using SSH Secure Shell to connect to a Linux machine ... when I try to run the compiled code I have, I keep getting these errors ...

./p2.c: line 5: syntax error near unexpected token `('
./p2.c: line 5: `void *printMessage( void *thread_id );'

here are the first few lines of the code ...

Expand|Select|Wrap|Line Numbers
  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <pthread.h>
  5.  
  6. void *printMessage( void *thread_id );
  7.  
  8. int main ( int argc, char *argv[] )
  9. {
  10. ...
  11.  
  12.  
I compiled this code using "gcc -pthread p2.c"
then, tried to run it using "./p2.c"
but get that error

the program deals with threads, but I don't think that has anything to do with it. I'm don't have much experience with Linux, and have no clue why I keep getting this error. Any help would be appreciated.
Mar 21 '08 #1
4 8301
sicarie
4,677 Expert Mod 4TB
I'm using SSH Secure Shell to connect to a Linux machine ... when I try to run the compiled code I have, I keep getting these errors ...

./p2.c: line 5: syntax error near unexpected token `('
./p2.c: line 5: `void *printMessage( void *thread_id );'

here are the first few lines of the code ...

Expand|Select|Wrap|Line Numbers
  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <pthread.h>
  5.  
  6. void *printMessage( void *thread_id );
  7.  
  8. int main ( int argc, char *argv[] )
  9. {
  10. ...
  11.  
  12.  
I compiled this code using "gcc -pthread p2.c"
then, tried to run it using "./p2.c"
but get that error

the program deals with threads, but I don't think that has anything to do with it. I'm don't have much experience with Linux, and have no clue why I keep getting this error. Any help would be appreciated.
This is not a Linux issue, this is a C issue. Look at your function parameters. You are attempting to pass a void *thread_id . A pointer to a void. Since void is used to specify no parameters it's getting confused when you try to send it a thread_id.

So the question is - what is the type of the thread_id. When you declare it in your main what type is it?
Mar 22 '08 #2
manontheedge
175 100+
I don't think it has to do with the type. I tried some different things out ...

I kept the same header files, made a simple function that takes an INT as its only argument and returns an int ... and in main, all I did was pass an int and get it's value back. I got the EXACT SAME ERROR.

So, I ran the same code again, but took out the <pthread.h> header file, and it compiled fine.

This is why I still believe it may be a Linux issue. I may be compiling it wrong, I don't know. I usually use "gcc -o programName programName.c", but I think I need to use "gcc -pthread programName2.c" to compile a program using pthreads.

I'm still lost, and I really do appreciate the help.
Mar 22 '08 #3
sicarie
4,677 Expert Mod 4TB
Dang, sorry about that. I think that would have been an issue anyway, but there is another issue. If you look at the error - the problem isn't with the argument, it's with the open parentheses. Or, what's right before the parentheses.


./p2.c: line 5: syntax error near unexpected token `('
./p2.c: line 5: `void *printMessage( void *thread_id );'

Expand|Select|Wrap|Line Numbers
  1. void *printMessage( void *thread_id );
  2.  
Why are you using a pointer for printMessage()? Try removing the * and see what that does.

PS - you do have the definition of this somewhere, right?
Mar 22 '08 #4
manontheedge
175 100+
hey, thank you for the responses. Yes I do have the function defined elsewhere :) I actually never write code like that, but I separated the declaration from the definition trying to pinpoint the problem.

Anyway, I just figured out the problem. It was the way I was compiling. I had to use "gcc -o p2 p2.c -lpthread" to get it to compile right. I had used a ton of combinations of that, but never exactly that. Works perfectly now.

By the way, I had that function as a function pointer because where it's taken in as an argument in "pthread_create", it's looking for a pointer to a function. So, anyway, the code itself was okay.

Again, thanks for the replies, I appreciate the help.
Mar 22 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Janwillem Borleffs | last post by:
Q: I'm getting an unexpected $ or $end parse/syntax error, what's causing this? A: This is caused when an expression is started with an opening brace, but the closing brace is omitted. ...
4
by: Bob Stearns | last post by:
The statement: merge into nullid.animals_et_in t1 using is3.animals t2 on t1.sire_assoc=t2.assoc and t1.sire_prefix=t2.prefix and t1.sire_regnum=t2.regnum when matched then update set...
5
by: r.nikhilk | last post by:
Hi, Currently, we are porting C++ applications from 32 bit to 64 bit on AIX platform. (The current version of AIX is 5.3 and xlC verison is 8.0). We are able to compile the applications by...
3
by: Manuel | last post by:
I'm trying to compile glut 3.7.6 (dowbloaded from official site)using devc++. So I've imported the glut32.dsp into devc++, included manually some headers, and start to compile. It return a very...
4
by: lisa | last post by:
I have an XML file that starts like this: <?xml version="1.0" encoding="ISO-8859-1" xmlns:fn="http://www.w3.org/2005/xpath-functions"?> <Authors> <Author> <ID>2</ID>...
3
by: GotDotNet? | last post by:
I'm trying to insert data from one table to another on sql server via C#. here is my syntax: insert into tableA (CustOrderNumber, custName, custState, CustCity) SELECT ('" +...
4
by: bhunesh | last post by:
hey , i m getting error listed below plz help me /virtualHosts/beta.myiris.com/htdocs/commodities/commd_admin/CRONJOB/new_cronjob/new_mcx.pl: line 14: syntax error near unexpected token...
1
by: FightClubDiego | last post by:
Hey.. I've been working on these sign up / log in forms for my new Game Site, and everything else in the game works but the registration!! I keep ketting the unexpected $end and Im tired of it! Here...
3
by: nvr | last post by:
Hi all I am doing the socket programming for the client side. but the code is not compiling and i am getting the below error ./Clientsend.c: line 11: syntax error near unexpected token `('...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.