We help IT Professionals succeed at work.

c - error: expected <)>  while parsing function declaration

basil365
basil365 asked
on
Medium Priority
418 Views
Last Modified: 2012-05-12
Hi,

Im trying to compile a c file and have hit the following error:

error: expected <)>  while parsing function declaration

this is my function and the compiler complains about this '&simDetails'

void ApplyGoalToPenalty(int penaltyTeam, int time,SimulationDetails &simDetails)
{

stuff

}

Open in new window


im unused to c so havent got my head around the errors produced yet, can anybody shed some light?

Thanks

Comment
Watch Question

AndyAinscowFreelance programmer / Consultant
CERTIFIED EXPERT

Commented:
Have a look at the lines before this code - is there an unmatched parenthesis  
Andy is correct.  If you are still stuck then

1. If this is an academic project, how about sharing the entire file?  (You could zip it if it's large).

2. If it's proprietary, the entire function before would help.

Of course, neither is necessary if you solve the problem using just Andy's advice.  (And please don't give me points if all I've done (that's useful to you) is agree with Andy.)

Author

Commented:
Thanks for your replies - i cant spot a missing parenthesis (I moved the location of the function in the file and still got the same error)

these is the function immediately before:

actor_init<IHCore>(float _hRate,float _aRate,int _periodNumber,long _clockTime,
						  int _isE,float _home,float _away,float _total,
						  float _over,int _goalLastPeriod,int _lastHomeGoalTime,int _lastAwayGoalTime)
{
	hRate = _hRate;
	aRate = _aRate;
	periodNumber = _periodNumber;
	clockTime = _clockTime;
	isE	= _isE;
	home = _home;
	away = _away;
	total = _total;
	over = _over;
	goalLastPeriod = _goalLastPeriod;
	lastHomeGoalTime = _lastHomeGoalTime;
	lastAwayGoalTime = _lastAwayGoalTime;
}

Open in new window


I'm using a library that implements the above 'actor' pattern
AndyAinscowFreelance programmer / Consultant
CERTIFIED EXPERT

Commented:
>>I moved the location of the function in the file and still got the same error

OK, looks like my first guess wasn't the problem.

What is SimulationDetails, can you post more details about it please.

Author

Commented:
its a struct declared in a header file

that has been included

typedef struct
{
	
	PenaltyData *homePenalties;
	PenaltyData *awayPenalties;
	int _goalLastPeriod_;//0 for false, 1 for true
	int _lastHomeGoalTime_;
	int _lastAwayGoalTime_;
	int _homeScore_;
	int _awayScore_;
	int _homeInitScore_;
	int _awayInitScore_;
	int _homeInBin_;
        int _awayInBin_;
	seed s;// = rand_seed[0];
	int _period1HomeScore;
	int _period1AwayScore;
	int _period2HomeScore;
	int _period2AwayScore;
	int _period3HomeScore;
	int _period3AwayScore;

} SimulationDetails;

Open in new window

AndyAinscowFreelance programmer / Consultant
CERTIFIED EXPERT

Commented:
What is the error number of the error ?
AndyAinscowFreelance programmer / Consultant
CERTIFIED EXPERT

Commented:
Oh, and what compiler are you using?
CERTIFIED EXPERT
Commented:
Hi basil365,

the SimulationDetails &simDetails declares the parameter to be a reference to SimulationDetails - references cannot be used in C, they were introduced with C++. Do you compile this with a C compiler? If so you'll have to use a pointer instead using SimulationDetails *simDetails.

ZOPPO
CERTIFIED EXPERT

Commented:
Sorry, I just saw you even use templates, so I think you're using C++ compiler - please ignore my last comment ...
evilrixSenior Software Engineer (Avast)
CERTIFIED EXPERT

Commented:
actor_init<IHCore>(float _hRate,float _aRate,int _periodNumber,long _clockTime,
                                                  int _isE,float _home,float _away,float _total,
                                                  float _over,int _goalLastPeriod,int _lastHomeGoalTime,int _lastAwayGoalTime)
{
}

Open in new window


Appears to be a template specialisation. It needs to have template <> before it.

template<>
actor_init<IHCore>(float _hRate,float _aRate,int _periodNumber,long _clockTime,
                                                  int _isE,float _home,float _away,float _total,
                                                  float _over,int _goalLastPeriod,int _lastHomeGoalTime,int _lastAwayGoalTime)
{
}

Open in new window

Author

Commented:
no, you are right - i am writing it in vs c++ but this one file is compiled using a c compiler as it must run on a gpu.

Apologies - I'm a novice in both c and c++ plus not used to the differences
evilrixSenior Software Engineer (Avast)
CERTIFIED EXPERT

Commented:
>>  but this one file is compiled using a c compiler as it must run on a gpu.
That is not possible, this is C++ code and will not compile as C code.

Author

Commented:
the actor_init<> is part of a specialised library (i am using a compiler from the source), which compiles correctly

The rest of the code in my file should be c (although as i said i'm not too sure of the difference).

My situation is that i have a c++ project (actually its in c# but thats not important currently) with a main. i then connect to a .hpp file. This file is generated from the custom compiler and contains 3 enforced functions (Actor_init,Actor_run and Actor()). everything else in this file (whatever is called from actor_run) must be compilable into c
CERTIFIED EXPERT

Commented:
@basil365: Above you wrote trying to compile a c file - this indicates the problem could come from the fact the file is compiled with a C compiler since some compilers/IDEs (as i.e. Microsoft VisualStudio) per default compile *.C files with a C-compiler.

Anyway evilrix is correct saying this is C++ code since the template-like stuff like actor_init<IHCore>(...) would lead to compile errors too when compiled with a C compiler - since you wrote these is the function immediately before I suspect you have both the actor_init<IHCore>(...) and the void ApplyGoalToPenalty(int penaltyTeam, int time,SimulationDetails &simDetails) within one and the same *.C file - is this correct?
AndyAinscowFreelance programmer / Consultant
CERTIFIED EXPERT

Commented:
>>actually its in c#

I hope you are aware C# and C++ are different programming languages.  C# doesn't even compile the way C++ will do - it gives an intermediate 'semi-compiled' file that requires a complete framework to run under.


>>must be compilable into c

Afraid you have to rewrite some parts of your app in C then, not C++

Author

Commented:
>>I hope you are aware C# and C++ are different programming languages.  C# doesn't even compile the way C++ will do - it gives an intermediate 'semi-compiled' file that requires a complete framework to run under.

Yup - i shouldn't even have opened that can of worms!


@Zoppo - thats where the 3rd party compiler comes in - its in a custom file format. Im actually running their compiler manually as i cant seem to get VS to try build it.

Apologies for causing confusion - suffice to say that the template- like stuff mentioned above does not cause issues with this compiler (I can compile samples with the same general syntax fine).

My  issues seem to be caused by the rest of the code in that file not being compatible with c.

I have already removed vectors from the file.
there was a suggestion above about references.
Is it ok to use structures?
Everything else is standard addition/subtraction etc and manipulation of numbers
CERTIFIED EXPERT
Commented:
Unfortunateley I still don't understand the C/C++ confusion: You say the file is compiled with a C compiler and the file in question contains the code for actor_init<IHCore>(...) and void ApplyGoalToPenalty(...) - in this case the template-stuff must generate errors (except the code maybe isn't compiled at all i.e. because it's excluded by some #ifdef/#endif).

IMO it's ok to use structures, just instead of references you'll have to use pointers.

And a hint about running their compiler manually as i cant seem to get VS to try build it.: If you add the file to your project you can specify any tool to 'build' it. Just open the file's properties (i.e. via context menu in Solution Explorer), in 'General' select 'Custom Build Tool' as 'Item Type', press 'Apply', then you can enter a command line which will be used to build any output from that file.

Here you can find more info about using Custom Build Tools in VS: http://msdn.microsoft.com/en-us/library/hefydhhy.aspx

Author

Commented:
thanks for your help

Explore More ContentExplore courses, solutions, and other research materials related to this topic.