Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Weird Syntax Error In C in If-else

I was programming an apache module. In the middle of the programming, I was opening a file, but I got an error while compiling.

32. static int wqb_handler(request_rec* req){
33. // Open and read our requested file
34. const char* p_file = req->filename;
35. 
36. FILE* req_file;
37. if((req_file = fopen(p_file,"r"))==NULL){
38.    return HTTP_NOT_FOUND;
39. }else{
40.     fclose(req_file);
41. }
42. // Required variables
43. const char* content_type_a = "text/html";
44.
45. // Set Headers
46. ap_set_content_type(req,content_type_a);
47. if(req->header_only){
48.    return OK;
49. }
50. 
51. 
52. return OK;
53. }

The problem is in that function, I was checking that was the problem, and I think the problem is the if-else statement, the code is written in C, not in C++.

These are the errors:

C:/wqb/wqb1_apache2.c(43) : error C2143: syntax error : missing ';' in front of 'const'
C:/wqb/wqb1_apache2.c(46) : error C2065: 'content_type_a' : undeclarated identifier
like image 357
Spamdark Avatar asked Mar 24 '13 19:03

Spamdark


1 Answers

If this is C, and you're not compiling in C99 mode (i.e. with a C89 compiler), remember that all declarations must be directly following the start of a block. Mixing declarations and code is a C99 feature imported from C++.

It appears you are compiling with a Micrososft Visual Studio Compiler in C mode. Note that William H. Gates III chose to ignore C99 entirely and refuses to update the C implemenation for the third millennium. :-)

like image 109
Jens Avatar answered Oct 11 '22 06:10

Jens