I am using the Eclipse CDT and I have a goto label and a FILE definition after it and when I compile the project it gives me the error: Expression expected before FILE.
Thanks in advance,
Mr. Man
EDIT:
Ok, so this is what I get from the command line:
iOS.c: In function ‘main’:
iOS.c:45: error: expected expression before ‘FILE’
iOS.c:49: error: ‘preFile’ undeclared (first use in this function)
iOS.c:49: error: (Each undeclared identifier is reported only once
iOS.c:49: error: for each function it appears in.)`
And this is what code throws the error:
fileExists:
FILE *preFile = fopen("prefix.txt","r");
As you're coding in C, you need to declare the variable at the beginning of the function:
void foo()
{
FILE* preFile;
// some code
fileExists:
preFile = fopen("prefix.txt","r");
}
Related
Every time i try to compile SDL_net it says
SDLnet.c: In function 'SDLNet_GetLocalAddresses':
SDLnet.c:215:69: error: 'ERROR_BUFFER_OVERFLOW' undeclared (first use in this function)
if ((dwRetVal = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen)) == ERROR_BUFFER_OVERFLOW) {
^~~~~~~~~~~~~~~~~~~~~
SDLnet.c:215:69: note: each undeclared identifier is reported only once for each function it appears in
SDLnet.c:223:21: error: 'NO_ERROR' undeclared (first use in this function)
if (dwRetVal == NO_ERROR) {
^~~~~~~~
make: *** [SDLnet.lo] Error 1
https://www.vogons.org/viewtopic.php?f=31&t=55706#p609435
Use my Mingw guide, it's in the Google Drive link
I have been working on a C code for which I needed some functions of libxls.h header files. I have already downloaded the corresponding files and followed the installation instruction. The files also contained a test C code (test.c) which I tried compiling. The results were as follow:
Command to compile the test.c file-
gcc test.c -lm
Results:
[root#XXXXXXX95549 test]# gcc test.c -lm
test.c:28:24: error: libxls/xls.h: No such file or directory
test.c: In function ‘main’:
test.c:33: error: ‘xlsWorkBook’ undeclared (first use in this function)
test.c:33: error: (Each undeclared identifier is reported only once
test.c:33: error: for each function it appears in.)
test.c:33: error: ‘pWB’ undeclared (first use in this function)
test.c:34: error: ‘xlsWorkSheet’ undeclared (first use in this function)
test.c:34: error: ‘pWS’ undeclared (first use in this function)
test.c:39: error: ‘WORD’ undeclared (first use in this function)
test.c:39: error: expected ‘;’ before ‘t’
test.c:53: error: ‘t’ undeclared (first use in this function)
test.c:58: error: ‘tt’ undeclared (first use in this function)
test.c:60: error: dereferencing pointer to incomplete type
test.c:63: error: dereferencing pointer to incomplete type
test.c:64: error: dereferencing pointer to incomplete type
test.c:66: error: dereferencing pointer to incomplete type
test.c:67: error: dereferencing pointer to incomplete type
test.c:68: error: dereferencing pointer to incomplete type
test.c:70: error: dereferencing pointer to incomplete type
test.c:70: error: dereferencing pointer to incomplete type
test.c:71: error: dereferencing pointer to incomplete type
To solve this problem, I copied the library files at the '/user/include' location
After which the results for same compilation commands were:
[root#XXXXXX95549 test]# gcc test.c -lm
/tmp/cc8DJETV.o: In function `main':
test.c:(.text+0x14): undefined reference to `xls_open'
test.c:(.text+0xd4): undefined reference to `xls_getWorkSheet'
test.c:(.text+0xe4): undefined reference to `xls_parseWorkSheet'
test.c:(.text+0xf0): undefined reference to `xls_getCSS'
test.c:(.text+0x49c): undefined reference to `xls_showBookInfo'
collect2: ld returned 1 exit status
Please, explain how can I rectify this problem.
The code test.c is given below:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <libxls/xls.h>
int main()
{
xlsWorkBook* pWB;
xlsWorkSheet* pWS;
FILE *f;
int i;
struct st_row_data* row;
WORD t,tt;
pWB=xls_open("files/test2.xls", "ASCII"); // "KOI8-R"
if (pWB!=NULL)
{
f=fopen ("test.htm", "w");
for (i=0;i<pWB->sheets.count;i++)
printf("Sheet N%i (%s) pos %i\n",i,pWB->sheets.sheet[i].name,pWB->sheets.sheet[i].filepos);
pWS=xls_getWorkSheet(pWB,0);
xls_parseWorkSheet(pWS);
fprintf(f,"<style type=\"text/css\">\n%s</style>\n",xls_getCSS(pWB));
fprintf(f,"<table border=0 cellspacing=0 cellpadding=2>");
for (t=0;t<=pWS->rows.lastrow;t++)
{
row=&pWS->rows.row[t];
// xls_showROW(row->row);
fprintf(f,"<tr>");
for (tt=0;tt<=pWS->rows.lastcol;tt++)
{
if (!row->cells.cell[tt].ishiden)
{
fprintf(f,"<td");
if (row->cells.cell[tt].colspan)
fprintf(f," colspan=%i",row->cells.cell[tt].colspan);
// if (t==0) fprintf(f," width=%i",row->cells.cell[tt].width/35);
if (row->cells.cell[tt].rowspan)
fprintf(f," rowspan=%i",row->cells.cell[tt].rowspan);
fprintf(f," class=xf%i",row->cells.cell[tt].xf);
fprintf(f,">");
if (row->cells.cell[tt].str!=NULL && row->cells.cell[tt].str[0]!='\0')
fprintf(f,"%s",row->cells.cell[tt].str);
else
fprintf(f,"%s"," ");
fprintf(f,"</td>");
}
}
fprintf(f,"</tr>\n");
}
fprintf(f,"</table>");
printf("Count of rows: %i\n",pWS->rows.lastrow);
printf("Max col: %i\n",pWS->rows.lastcol);
printf("Count of sheets: %i\n",pWB->sheets.count);
fclose(f);
xls_showBookInfo(pWB);
}
return 0;
}
Thanks in advance,
Got the answer to this question on the following location:
http://www.cprogramdevelop.com/2018568/
Those who might be facing the problem with libxls library can refer the above mentioned website.
cheers
gcc 4.7.2
c89
Hello,
I am reviewing someones source code, and I have come across this.
I have this declaration and definition that I don't understand what it does. I know that the static means that it will not be exported out of the file.
static SERVICE_STATUS_HANDLE g_win_status_handle = NULL;
Because it is set to NULL it looks like a pointer. SERVICE_STATUS_HANDLE isnt' defined anywhere else. Only this file.
It is being used like this, is this comparing if g_win_status_handle is equal to NULL after SERVICE_STATUS_HANDLE is casted to 0 or NULL:
if(g_win_status_handle == (SERVICE_STATUS_HANDLE)0) {
/* do something */
}
And like this:
if(!SetServiceStatus(g_win_status_handle, &g_win_status)) {
/* do something */
}
Many thanks if someone can shed some light on this.
i have made small program
#include<stdio.h>
static SERVICE_STATUS_HANDLE g_win_status_handle = NULL;
int main()
{
if(g_win_status_handle == (SERVICE_STATUS_HANDLE)0) {
printf("ksdfbhdejkfb");
}
return 0;
}
compiled on gcc (GCC) 4.5.1 20100924 (Red Hat 4.5.1-4)
with c89 flags, like
gcc -std=c89 temp.c
its giving error
temp.c:3:30: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘g_win_status_handle’
temp.c: In function ‘main’:
temp.c:6:4: error: ‘g_win_status_handle’ undeclared (first use in this function)
temp.c:6:4: note: each undeclared identifier is reported only once for each function it appears in
temp.c:6:28: error: ‘SERVICE_STATUS_HANDLE’ undeclared (first use in this function)
temp.c:6:50: error: expected ‘)’ before numeric constant
Here it is obvious that SERVICE_STATUS_HANDLE must be defined some where.. if not defined then how your code is going to even compile?
May be it will be defined in some header file..
Updated answer from comments
SERVICE_STATUS_HANDLE is defined in windows.h and its going to include.
http://msdn.microsoft.com/en-us/library/windows/desktop/aa383751%28v=vs.85%29.aspx
I have a simple code in c :
#include <stdio.h>
main()
{
printf(“Hello, world! /n”);
}
but I can't compile it in GCC. The warning when i try to compile it :
1. gcc hello.c -o hello
2. hello.c: In function 'main:
3. hello.c:4:1: error: stray '\342' in program
4. hello.c:4:1: error: stray '\200' in program
5. hello.c:4:1: error: stray '\234' in program
6. hello.c:4:11: error: 'Hello' undeclared (first use in this function)
7. hello.c:4:11: note: each undeclared identifier is reported only once for each function
it appears in
8. hello.c:4:18: error: 'world' undeclared (first use in this function)
9. hello.c:4:23: error: expected ')' before '!' token
10. hello.c:4:23: error: stray '\342' in program
11. hello.c:4:23: error: stray '\200' in program
12. hello.c:4:23: error: stray '\235' in program
anyone can help me please?
You get those errors because you presumably copy and pasted that code from a formatted source. “ and ” aren't the same as ". Change them to that and the code will compile.
You should probably also follow the convention of having main defined as:
int main(void)
and therefore returning an int.
You probably also want to change /n to \n
Since yesterday, I've been facing a compiling error for my C project. The project itself consists on creating a service that will make some tasks.
I don't what has changed since yesterday, but this morning, my code can't compile anymore.
Here are the errors I have :
c:\path\main.c(56): error C2275: 'SERVICE_TABLE_ENTRY' : illegal use of this type as an expression
c:\program files\microsoft sdks\windows\v7.0a\include\winsvc.h(773) : see declaration of 'SERVICE_TABLE_ENTRY'
c:\path\main.c(56): error C2146: syntax error : missing ';' before identifier 'DispatchTable'
c:\path\main.c(56): error C2065: 'DispatchTable' : undeclared identifier
c:\path\main.c(56): error C2059: syntax error : ']'
c:\path\main.c(57): error C2065: 'DispatchTable' : undeclared identifier
c:\path\main.c(57): warning C4047: 'function' : 'const SERVICE_TABLE_ENTRYA *' differs in levels of indirection from 'int'
c:\path\main.c(57): warning C4024: 'StartServiceCtrlDispatcherA' : different types for formal and actual parameter 1
Here's the code concerned by these errors (from lines 45 to 58) :
int main(int ac, char *av[])
{
if (ac > 1)
{
if (!parse_args(ac, av))
{
aff_error(ARGUMENTS);
return EXIT_FAILURE;
}
}
SERVICE_TABLE_ENTRY DispatchTable[] = {{MY_SERVICE_NAME, ServiceMain}, {NULL, NULL}};
StartServiceCtrlDispatcher(DispatchTable);
return EXIT_SUCCESS;
}
And here's the code of my ServiceMain function :
void WINAPI ServiceMain(DWORD ac, LPTSTR *av)
{
gl_ServiceStatus.dwServiceType = SERVICE_WIN32;
gl_ServiceStatus.dwCurrentState = SERVICE_START_PENDING;
gl_ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP;
gl_ServiceStatus.dwWin32ExitCode = 0;
gl_ServiceStatus.dwServiceSpecificExitCode = 0;
gl_ServiceStatus.dwCheckPoint = 0;
gl_ServiceStatus.dwWaitHint = 0;
gl_ServiceStatusHandle = RegisterServiceCtrlHandler(MY_SERVICE_NAME, ServiceCtrlHandler);
if (gl_ServiceStatusHandle == (SERVICE_STATUS_HANDLE)0)
return;
gl_ServiceStatus.dwCurrentState = SERVICE_RUNNING;
gl_ServiceStatus.dwCheckPoint = 0;
gl_ServiceStatus.dwWaitHint = 0;
SetServiceStatus(gl_ServiceStatusHandle, &gl_ServiceStatus);
}
I couldn't manage to find some answers that fit my problem, could anyone helps ? Thanks !
When you name your source files *.c, MSVC assumes it's compiling C, which means C89. All block-local variables need to be declared at the beginning of the block.
Workarounds include:
declaring/initializing all local variables at the beginning of a code block (directly after an opening brace {)
rename the source files to *.cpp or equivalent and compile as C++.
upgrading to VS 2013, which relaxes this restriction.
You might be using a version of C that doesn't allow variables to be declared in the middle of a block. C used to require that variables be declared at the top of a block, after the opening { and before executable statements.
Put braces around the code where the variable is used.
In your case that means:
if (ac > 1)
{
if (!parse_args(ac, av))
{
aff_error(ARGUMENTS);
return EXIT_FAILURE;
}
}
{
SERVICE_TABLE_ENTRY DispatchTable[] = {{MY_SERVICE_NAME, ServiceMain}, {NULL, NULL}};
StartServiceCtrlDispatcher(DispatchTable);
}
This error occurred when transferring a project from one installation to another (VS2015 => VS2010).
The C code was actually compiled as C++ on the original machine, on the target machine the "Default" setting in Project Properties\C/C++\Advanced\Compile as was somehow pointing to C even though the source file was of type *.cpp.
In my small program, errors popped up regarding the placement in code of certain types e.g. HWND and HRESULT as well as on the different format of for loops , and C++ constructs like LPCTSTR, size_t, StringCbPrintf and BOOL. Comparison.
Changing the "Compile as" from Default to Compile as C++ Code (/TP) resolved it.
This will also give you "illegal use of this type as an expression".
WRONG:
MyClass::MyClass()
{
*MyClass _self = this;
}
CORRECT:
MyClass::MyClass()
{
MyClass* _self = this;
}
You might be wonder the point of that code. By explicitly casting to the type I thought it was, when the compiler threw an error, I realized I was ignoring some hungarian notation in front of the class name when trying to send "this"
to the constructor for another object. When bug hunting, best to test all of your assumptions.