How would you fix this?

Started by
8 comments, last by Pink Horror 10 years, 4 months ago

#define list_entry(ptr, type, member) \
	((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))

#define list_for_each_entry_safe(pos, n, head, member)   \
					for (pos = list_entry((head)->next, typeof(*pos), member), \
					n = list_entry(pos->member.next, typeof(*pos), member); \
					&pos->member != (head);      \
					pos = n, n = list_entry(n->member.next, typeof(*n), member))



list_for_each_entry_safe(ent, iter, &(tq->q), q_node) {
		list_del(&ent->q_node);
		free(ent);
	}




The errors:


1>c:\users\enjoydrama\documents\visual studio 2013\projects\test\test\util.c(1226): error C2059: syntax error : ')'
1>c:\users\enjoydrama\documents\visual studio 2013\projects\test\test\util.c(1229): error C2059: syntax error : ')'
1>c:\users\enjoydrama\documents\visual studio 2013\projects\test\test\util.c(1231): warning C4552: '!=' : operator has no effect; expected operator with side-effect
1>c:\users\enjoydrama\documents\visual studio 2013\projects\test\test\util.c(1232): error C2059: syntax error : ')'
1>c:\users\enjoydrama\documents\visual studio 2013\projects\test\test\util.c(1243): error C2059: syntax error : 'for'
1>c:\users\enjoydrama\documents\visual studio 2013\projects\test\test\util.c(1243): error C2059: syntax error : '&'
1>c:\users\enjoydrama\documents\visual studio 2013\projects\test\test\util.c(1243): error C2065: 'iter' : undeclared identifier
1>c:\users\enjoydrama\documents\visual studio 2013\projects\test\test\util.c(1243): error C2099: initializer is not a constant
1>c:\users\enjoydrama\documents\visual studio 2013\projects\test\test\util.c(1243): error C2100: illegal indirection
1>c:\users\enjoydrama\documents\visual studio 2013\projects\test\test\util.c(1243): error C2059: syntax error : ')'

I did not write the code,I'm just trying to make it compile.

Advertisement
Check that there's no whitespace after the \'s. If there is, that might be screwing VS up. It seems to have copy pasted without it, but maybe to original has it.

You could try putting the macros all on one line to rule out odd whitespace or indentation issues.

-Josh

--www.physicaluncertainty.com
--linkedin
--irc.freenode.net#gdnet

...that did not work either

Maybe the problem is on a line above the posted code.

above the posted code there are just comments

What lines are those errors actually in? The error may be caused by the context in which you're expanding them.

Sean Middleditch – Game Systems Engineer – Join my team!

The best solution is to compile it with gcc like it was meant to be.

The Microsoft and gcc preprocessors do not work identically. This code fragment (the macro definitions themselves actually come from the linux kernel) was written to compile with gcc, and so in the Microsoft compiler the macros do not get expanded as intended. It will likely take much more work to rewrite them to expand properly with the Microsoft compiler than to use to right compiler to begin with.

Because this is a compilation error of the precompiled source, the precompiled source is already available. Just dump the precompiled source to a file, and look at the line where the bug happens. Possibly you can find out what was the bug with this.

In the C or C++ file's Property sheet select C/C++ in the tree and then select Preprocessor. There is a switch 'Preprocess to a File'. When you switch it on, it will generate a preprocessed output, instead of compiling the file at the next build. The file will be named after your source file with a .i extension and is put in the intermediate directory where the object files are. (I think it's possible to put elsewhere with a different name, but not in the Express version.)

I believe the problem comes from using "typeof", which is a C extension of GCC.

This topic is closed to new replies.

Advertisement