473,806 Members | 2,879 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

175 New Member
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 8355
sicarie
4,677 Recognized Expert Moderator Specialist
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 New Member
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 Recognized Expert Moderator Specialist
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 New Member
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
2297
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. Examples: if ($condition) { .... // No closing brace; the error is thrown
4
5331
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 t1.sire_bhid=t2.bhid when not matched then update set t1.sire_bhid=0 go gets the error message:
5
4523
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 including the -q64 option in xlC compiler. And we are able to link all these libraries to one of the main applications and generate an executable. SKLoader. But, when we try to run this main executable, we are getting the following errors:
3
16255
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 strange error. In your experience, where I should looking to find the real error? Surely the sintax of glut is correct... gcc.exe -c glut_bitmap.c -o glut_bitmap.o -I"C:/Dev-Cpp/include" -I"../../include" -D__GNUWIN32__ -W -DWIN32 -DNDEBUG...
4
8979
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> <UserName>Whoever</UserName> <Title>Whatever</Title> <Internet>email</Internet>
3
1558
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 ('" + System.GUID.NewGUID() + '", Name, State, City) from custSales I'm getting this error message: There was an error parsing the query.
4
6832
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 `"/usr/bin/wget -O /tmp/mcx.dat http://www.mcxindia.com/xmlurl/GetTouchLine.aspx?userid=IRIS&pwd=CZ33M3KZ53"' #!/usr/bin/perl #Purpose : To create MCX DAT file from mcx feed coming from mcxindia.com #Author : Yatin Patil
1
6473
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 is the code... SOMEBODY PLEASE HELP ME!! I'm going crazy! haha <?php //This contains user stuffs switch($_GET) { case 'newuser': new_user_form(); break; case 'newusersub': new_user_submit(); break; case 'edituser': edit_user_begin(); break;...
3
5134
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 `(' ./Clientsend.c: line 11: `int main()' Code: #include <stdio.h> #include <stdlib.h>
0
9719
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10620
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10369
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10372
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10110
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7650
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5546
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5682
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4329
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.