I have this code:
FILE *f = fopen(intPath, "r");
Node *n;
if (f) {
try {
n = parse(f, intPath);
} catch (SyntaxError e) {
fclose(f); /***** line 536 *****/
throw LangException(
builtin_classes::exception_class::create_ImportError(
String::fromAscii(e.filename)->
append(String::fromAscii(":"))->
append(String::fromInt(e.line))->
append(String::fromAscii(":"))->
append(String::fromInt(e.col))->
append(String::fromAscii(": syntax error: "))->
append(String::fromAscii(e.message))
);
}
fclose(f);
return n->eval(scope);
} else {
throw LangException(
builtin_classes::exception_class::create_ImportError(
String::fromAscii("failed to open file for reading")
),
line,
col
);
}
And the compiler gives this error:
nodes.cpp:537:40: error: expected primary-expression before ‘(’ token
nodes.cpp:544:94: error: expected ‘)’ before ‘;’ token
I have no clue what it could be, especially since that code sample has another statement which does the same thing, and it doesn't cause an error.
throw LangException(
builtin_classes::exception_class::create_ImportError(
String::fromAscii(e.filename)->
append(String::fromAscii(":"))->
append(String::fromInt(e.line))->
append(String::fromAscii(":"))->
append(String::fromInt(e.col))->
append(String::fromAscii(": syntax error: "))->
append(String::fromAscii(e.message))
) // This closes the function call
; // You didn't close the throw here!
Your ( and your ) don't match in that large, first throw LangException block.
The compiler tells you what is wrong. The throw LangException( doesn't have a ).
Exactly what it says. You are missing a ‘)’ before ‘;’ token on that line.
LangException(...
is not closed.
Related
When I tried to run unit test for a simple main program in C++:
#include <iostream>
int main()
{
std::cout << "hello world" << std::endl;
return 0;
}
it occurred the following problem:
C++test analysis errors in /Demo_aCpp
1. Test execution: error preparing instrumentation / symbols data for file.
"/usr/include/sys/features.h", line 25: error: expected an identifier
extern "C" {
^
"/usr/include/sys/features.h", line 25: error: expected a ";"
extern "C" {
^
"/usr/include/sys/reent.h", line 9: error: expected an identifier
extern "C" {
^
"/usr/include/sys/reent.h", line 9: error: expected a ";"
extern "C" {
^
...
Error limit reached.
100 errors detected in the compilation of "C:\Users\username\AppData\Local\Temp\ParaSoft.1840.28297.c".
Compilation terminated.
I have no idea about this. Any hint on this? Thanks in advance
I'm trying to run a graphics program on my Ubuntu 18.04 LTS system to print the error code for failed graphics operation. My code is
#include <graphics.h>
#include <stdlib.h>
int main()
{
int gd, gm, errorcode;
initgraph(&gd, &gm, NULL);
errorcode = graphresult();
if(errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to exit.");
getch();
exit(1);
}
getch();
closegraph();
return 0;
}
But when I run it I get the following error :
g++ -o mygraphics mygraphics.c -lgraph
mygraphics.c: In function ‘int main()’:
mygraphics.c:10:20: error: ‘graphresult’ was not declared in this scope
errorcode = graphresult();
^~~~~~~~~~~
mygraphics.c:12:24: error: ‘grOk’ was not declared in this scope
if(errorcode != grOk)
^~~~
mygraphics.c:12:24: note: suggested alternative: ‘brk’
if(errorcode != grOk)
^~~~
brk
mygraphics.c:14:42: error: ‘grapherrormsg’ was not declared in this scope
printf("Graphics error: %s\n", grapherrormsg(errorcode));
I searched all over the internet but not able to find a promising solution. Can someone help me out please. Thank you in advance :)
OK now here's a mystery that no one I ask can solve. I maybe a beginner but this is something I know I shouldn't get.
1>c:\users\kevin\documents\visual studio 2010\projects\movie\movie\p2 project.cpp(57): error C2143: syntax error : missing ';' before '{'
1>c:\users\kevin\documents\visual studio 2010\projects\movie\movie\p2 project.cpp(68): error C2181: illegal else without matching if
for this section here
int customer_menu(char signup(struct register_ regis))
{
FILE *cni; /* cni means customer necessary info*/
cni=fopen("login.txt","a+");
if(cni!=NULL)
{
if (regis.category=="customer" )
/*This is where the compiler say the error is at. Expecting a ';' here?:*/
{
printf("\t\t~>~>~>~>~>~>~>menu~>~>~>~>~>~>~>~>~~ \n");
printf("\t\t~>~>~>~>~>~>~>~>~>~>~>~>~>>~>~>~>~>~ \n");
printf("\t\t~>~>~>~>>~>~>~>~>~>~>~>~>~>~>~>~>~>~ \n");
printf("\t\t~>~>~>~>~>to login~>~>~>~>~>~press 1 \n");
printf("\t\t~>~>~>~>~>to register~>~>~>~>press 2 \n");
printf("\t\t~>~>~>~>~>to buy ticket~>~>~>press 6 \n");
printf("\t\t~>~>~>~>~>to exit~>~>~>~>~>~>press 0 \n");
printf("\t\t~>~>~>~>~>~>~>~>~>~>~>~>~>>~>~>~>~>~ \n");
printf("\t\t~>~>~>~>>~>~>~>~>~>~>~>~>~>~>~>~>~>~ \n");
scanf("%d",&choice);
}
else
{
int worker_menu(char signup(struct regis));
}
fclose(cni);
/* And illegal use of else without matching if here?*/
}
else
{
printf("an error occured. please try again\n");
system("pause");
system("cls");
char log,reg; desion(reg, log);
}
}
Do I have errors before the error comment that the compiler skip so result in such a shocking and puzzling mystery?
int customer_menu(char signup(struct register_ regis))
{
This is not a valid function declaration. It's not obvious how to fix it, either. What do you want this to mean?
I want to wirte a function with variable arguments in this way:
static void configElement(U32 localFaultId,
char* name,
U32 report,
U32 localId,
U32 detectTime,
U32 ceaseTime,...)
{
U32 i = 0;
U32 tmpNo = 0;
va_list ap;
if (nofFaults >= MAX_NOF_LOCAL_FAULTS)
{
//something here
return;
}
else
{
faultList[nofFaults].ceaseTime = ceaseTime;
va_start(ap, ceaseTime);
tmpNo = va_arg(ap, U32);
while ((tmpNo!= END_MARK) && (i < MAX_NOF_DEPEND))
{
faultList[nofFaults].dependList[i++].faultNo = tmpNo;
}
faultList[nofFaults].dependList[i].faultNo = END_MARK;
/* Finish by increment nofFaults parameter */
va_end(ap);
nofFaults++;
}
}
However, I got the error msg when compiling this code:
fault_manager.cc:3344: error: expected primary-expression before ',' token
fault_manager.cc:3387: error: expected primary-expression before 'U32'
fault_manager.cc:3387: error: expected `)' before 'U32'
fault_manager.cc:3387: error: expected `)' before ';' token
fault_manager.cc:3387: error: expected `)' before ';' token
I have no idea what is going wrong here. My platform is Windows, and I'm using cygwin+Eclipse(CDT). The version of gcc is 4.1.1.
Any idea will be appreciated much!
It looks like the compiler does not know what U32 is. Did you include all necessary headers?
I get the following errors when trying to compile the below code using g++. When I compile it using gcc it works fine (other than a few warnings). Any help appreciated.
g++ ush7.cpp
ush7.cpp: In function ‘int signalsetup(sigaction*, sigset_t*, void (*)(int))’:
ush7.cpp:93: error: expected unqualified-id before ‘catch’
ush7.cpp:95: error: expected primary-expression before ‘catch’
ush7.cpp:95: error: expected `;' before ‘catch’
ush7.cpp:97: error: expected primary-expression before ‘catch’
ush7.cpp:97: error: expected `;' before ‘catch’
ush7.cpp:100: error: expected primary-expression before ‘catch’
ush7.cpp:100: error: expected `)' before ‘catch’
ush7.cpp:108: error: expected `)' before ‘;’ token
ush7.cpp:108: error: expected `)' before ‘;’ token
ush7.cpp: In function ‘int makeargv(const char*, const char*, char***)’:
ush7.cpp:137: error: invalid conversion from ‘void*’ to ‘char*’
ush7.cpp:145: error: invalid conversion from ‘void*’ to ‘char**’
int signalsetup(struct sigaction *def, sigset_t *mask, void (*handler)(int))
{
struct sigaction catch;
catch.sa_handler = handler; /* Set up signal structures */
def->sa_handler = SIG_DFL;
catch.sa_flags = 0;
def->sa_flags = 0;
if ((sigemptyset(&(def->sa_mask)) == -1) ||
(sigemptyset(&(catch.sa_mask)) == -1) ||
(sigaddset(&(catch.sa_mask), SIGINT) == -1) ||
(sigaddset(&(catch.sa_mask), SIGQUIT) == -1) ||
(sigaction(SIGINT, &catch, NULL) == -1) ||
(sigaction(SIGQUIT, &catch, NULL) == -1) ||
(sigemptyset(mask) == -1) ||
(sigaddset(mask, SIGINT) == -1) ||
(sigaddset(mask, SIGQUIT) == -1))
return -1;
return 0;
}
catch is a keyword in C++ but not in C.
Please see my related answer C is not a proper subset of C++ here, or even better here.
You should be able to use a #define if you don't want to change the rest of the code.
#define catch _catch