Need help compiling in C. When using GCC at home (Windows, 3.4.5), the code compiles fine (even with -Wall). When using the uni's GCC (4.3.3, debian), I keep getting the following message - "expected ')' before '*' token". What might be the matter? (Needless to say, compiling it on school's farm is a must).
The exact error message:
MatrixMultiplactionMacro.h:5: error: expected ')' before '*' token
#ifndef _MATRIXMULTIPLACTIONMACRO_H
#define _MATRIXMULTIPLACTIONMACRO_H
void pseudoMain(
member* (*__allocateMember)(),
void (*__freeMember)(member*),
char* (*__memberToString)(member*),
void (*__setToZero)(member*),
void (*__multiplyMembers)(member*, member*, member*),
void (*__addMembers)(member*, member*, member*),
void (*__writeToMember)(char*, member*),
void (*__duplicateMember)(member*, member*)
);
#endif
The problematic line, therefore:
member* (*__allocateMember)(),
What am I doing wrong?
The first argument to pseudoMain is a pointer to a function returning 'member', which isn't a C or C++ keyword, and I don't see a definition for it. Perhaps you are missing a #include?
Related
https://github.com/noyesno/awka
For the above repo, I got the following error when I try to compile it on macOS (gcc is just clang). I have no idea how to fix the problem according to the error message. It compiles fine on Linux.
I also tried the real gcc from Homebrew to compile the package. It also show the same error. How can I fix this problem on macOS?
$ ./configure
$ make
...
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\" -c -o print.o print.c
print.c:52:11: error: expected parameter declarator
int PROTO(sprintf, (char *, const char *,...)) ;
^
print.c:52:11: error: expected ')'
print.c:52:11: note: to match this '('
print.c:52:11: error: conflicting types for '__builtin___sprintf_chk'
int PROTO(sprintf, (char *, const char *,...)) ;
^
print.c:52:11: note: '__builtin___sprintf_chk' is a builtin with type 'int (char *, int, unsigned long, const char *, ...)'
3 errors generated.
make[1]: *** [<builtin>: print.o] Error 1
make[1]: Leaving directory '/private/tmp/awka/awka'
make: *** [Makefile:48: awka_exe] Error 2
I'm not going to spend ages on this, but it looks as though configure is gripping stdio.h looking for sprintf. It is unable to find it in the header, and so it adds the #define:
NO_SPRINTF_IN_STDIO
which it sets to 1, and uses it to add its own prototype for sprintf. Unfortunately, this appears to be a macro in this case, which replaces sprintf with '__builtin___sprintf_chk' instead (which has additional string length checks by the looks of it).
Possible solutions:
Comment out the line in print.c, and make sure stdio.h is included somewhere.
After running configure, search for where it defines NO_SPRINTF_IN_STDIO and set that var to 1?
Fix the configure to so a more rigorous test?
I am following along a tutorial for C programming in 6502 Assembly and am having a great deal of difficulty on the 3rd step. When compiling my code in the command line, i get these errors:
test4.c(8): Error: '{' expected
test4.c(9): Warning: Function must be extern
test4.c(9): Error: ';' expected
test4.c(13): Error: '}' expected
I am using a program to compile .c files made in code::blocks to .nes files. The current tutorial is having me also make .s assembly file when compiling in the cl65 command line in Windows from the program that is compiling it. Here is the link to the tutorial page i am on:
https://helloacm.com/tutorial-3-c-programming-in-6502-using-assembly/
I have tried many different combinations of code that i can think of to try and get rid of a least some of the problems, but alas to no avail. I am an amateur in C, usually use C++ but i cannot and still trying to figure this out. I was not able to find the "Function must be extern" error anywhere with a quick google search either. Anyone have an idea what's going on?
Here is how i wrote the code in code::blocks:
void main()
{
asm("nop");
}
void testasm()
void main()
{
while(1) {
testasm(); // call the assembled function
}
}
Also, had a really difficult time following along on this particular tutorial part.
Thanks in advance, any help is appreciated on diagnosing the problem!
Perhaps this is what you're after?
void testasm()
{
asm("nop");
}
void main()
{
while(1) {
testasm(); // call the assembled function
}
}
Your code had two main() functions, and a prototype void testasm() with no terminating semicolon.
Alternatively, if testasm is written in assembly, your code should look like this (removing the extra main function):
extern void testasm(); // `extern` not specifically required, but may be for
// your particular compiler
void main()
{
while(1) {
testasm(); // call the assembled function
}
}
You need to be much more careful writing code.
I am running ANTLR 4.2 and using the canonical C grammar from:
https://github.com/antlr/grammars-v4/tree/master/c
I am doing the following steps: (using batch files from the ANTLR4 book)
antlr C.g4
javac C*.java
grun C compilationUnit -tokens test.c
Where test.c has the following code:
PASSING:
typedef
void
(*EFI_SET_MEM) (
void *Buffer,
UINTN Size,
UINT8 Value
);
FAILING:
error is: line 3:9 no viable alternative at input 'typedefvoid(__cdecl*'
typedef
void
(__cdecl *EFI_SET_MEM) (
void *Buffer,
UINTN Size,
UINT8 Value
);
The only difference is __cdecl. I tried several changes to fix this, e.g.:
functionSpecifier
: ('inline'
| '_Noreturn'
| '__inline__' // GCC extension
| '__cdecl'
| '__stdcall')
| gccAttributeSpecifier
| '__declspec' '(' Identifier ')'
;
...but this is not working. Any ideas on how to fix this problem? Since what I'm doing doesn't care about the calling convention, creating this lexer rule makes the problem go away:
Cdecl
: '__cdecl'
-> skip
;
I still wish I had a real solution.
__cdecl is used in C++ to declare an interface as using the C-calling convention for linkage (explicitly with undecorated names and the like). __cdecl is C++ (and I believe specific to certain compilers on top of that), not C, so the C grammar doesn't specify it.
I'm not sure why your proposed fix isn't working, tho.
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
My current job at the university is to port a C program from MinGW (windows) to Visual Studio (nmake).
I have got a valid "makefile.vc" file for a very similar C program.
My approach was to adopt the Makefile (i.e. "makefile.vc") to the program I need to port.
All but four C files seem to compile fine. Those four files have various errors for example, syntax errors and "unknown size".
Should I continue with my approach to change the Makefile or use CMAKE instead of nmake?
Is there a tutorial or any other pointer on porting a C program from MinGW/gcc to nmake?
typedef struct {
A_TypeConverter *converter;
char *domain;
} enumeratorConverterEntry;
static enumeratorConverterEntry enumeratorConverterEntries[]; /* line 186 */
error:
f.c(186) : error C2133: 'enumeratorConverterEntries' : unknown size
typedef struct AsmInstructionInfo {
int flags;
CONST char **argTypes; /* line 7 */
int minArgs;
int maxArgs;
int cArgs;
} AsmInstructionInfo;
error:
fAssemble.c(7) : error C2061: syntax error : identifier 'CONST'
..
/* file fStack.c: */
#ifdef CHECK_ACTIVATION_COUNTS
/* code */
#endif
/* more code */
void fShowStack(l_Interp *interp) { /* line 94 */
l_CallFrame *framePtr;
/* more code */
error:
fStack.c(94) : error C2143: syntax error : missing ')' before '*'
fStack.c(94) : error C2143: syntax error : missing '{' before '*'
fStack.c(94) : error C2059: syntax error : ')'
fStack.c(94) : error C2054: expected '(' to follow 'interp'
static enumeratorConverterEntry enumeratorConverterEntries[]; /* line 186 */
That looks like a valid incomplete, forward declaration of an array, which would be valid syntax, except I think for the static qualifier. I don't have a copy of the 'C' standard in front of me, but reading between the lines on the results of Googling "forward declaration of static array" seems to indicate that an incomplete definition of a static array results in undefined behavior, so Microsoft and GNU are legitimately entitled to do whatever they want with it. GNU accepts it, and Microsoft rejects it. As Mark Wilkins points out you should be make the Microsoft compiler happy by replacing it with:
extern enumeratorConverterEntry enumeratorConverterEntries[]; /* line 186 */
In general it's worth noting that the Microsoft compiler only supports the C89 standard, while the GNU compiler supports portions of the C99 standard, and several of their own extensions, depending on the arguments to the compiler.
The errors in fAssemble.c and fStack.c look like one or more preprocessor files are missing or incomplete. You should search your source to find out where CONST and l_Interp are defined, and then figure out why they are not being picked up in the files where the errors are occurring.
I just now tried out that array declaration with MinGW, and it does compile. To make it link, though, it needs the array to be defined elsewhere. The result is that it appears to be the same as the extern storage class:
extern enumeratorConverterEntry enumeratorConverterEntries[];
I'm not sure if there are other subtleties associated with the original declaration using a static storage class for the global.