I have a fnc:
template<class T, T constraint>
inline void CheckSize(const T& value)
{
if (value < constraint)
{
throw BadSize_ex(value);
}
}
but I cannot test it with Boost. What I'm doing is this ():
BOOST_REQUIRE_THROW(CheckSize<int,2>(1),std::BadSize_ex);
Where is the problem?
but I'm getting lots of miningless errors of type ',' missing before ';'.
Errors (Some of them but all of them are from this ball park)
Error 5 error C2143: syntax error : missing ',' before ';'
Error 6 error C2143: syntax error : missing '>' before '{'
Error 7 error C2143: syntax error : missing ';' before '{'
Error 8 error C2143: syntax error : missing ',' before ')'
Error 45 error C2143: syntax error : missing ';' before '}'
Error 46 error C1004: unexpected end-of-file found
It is the comma between template parameters. Try with additional paranthesis:
BOOST_REQUIRE_THROW( (CheckSize<int,2>(1)),std::BadSize_ex);
You need to use BOOST_PP_COMMA() in place of , if you want to pass commas within parameters instead of to delimit parameters. This is basically because the preprocessor can't recognize template parameter delimiting over macro parameter delimiting.
Related
I am having an enormous amount of errors showing up in the error list of the program, but none of the ones listed seem to be "real" errors. Some of the lines are red and then when I go to highlight over them the error disappears. I just can't seem to find where my error really is. What is the best process to go through to find my mistake?
Below is the error list in case that is helpful.
Error 38 error C1004: unexpected end-of-file found 85
Error 68 error C1004: unexpected end-of-file found 42
Error 63 error C1903: unable to recover from previous error(s); stopping compilation 72
Error 66 error C2059: syntax error : ')' 42
Error 2 error C2059: syntax error : '>' 80
Error 40 error C2059: syntax error : '>' 80
Error 65 error C2059: syntax error : '>' 42
Error 20 error C2065: '_Ptr_cerr' : undeclared identifier 27
Error 16 error C2065: '_Ptr_cin' : undeclared identifier 25
Error 22 error C2065: '_Ptr_clog' : undeclared identifier 28
Error 18 error C2065: '_Ptr_cout' : undeclared identifier 26
Error 28 error C2065: '_Ptr_wcerr' : undeclared identifier 32
Error 24 error C2065: '_Ptr_wcin' : undeclared identifier 30
Error 30 error C2065: '_Ptr_wclog' : undeclared identifier 33
Error 26 error C2065: '_Ptr_wcout' : undeclared identifier 31
Error 4 error C2065: 'faction' : undeclared identifier 84
Error 42 error C2065: 'faction' : undeclared identifier 84
Error 64 error C2065: 'Faction' : undeclared identifier 42
Error 13 error C2065: 'socialite' : undeclared identifier 100
Error 51 error C2065: 'socialite' : undeclared identifier 100
Error 1 error C2065: 'Socialite' : undeclared identifier 80
Error 12 error C2065: 'Socialite' : undeclared identifier 100
Error 39 error C2065: 'Socialite' : undeclared identifier 80
Error 50 error C2065: 'Socialite' : undeclared identifier 100
Error 8 error C2065: 'textWriter' : undeclared identifier 82
Error 46 error C2065: 'textWriter' : undeclared identifier 82
Error 6 error C2143: syntax error : missing ',' before ')' 84
Error 10 error C2143: syntax error : missing ',' before ')' 82
Error 14 error C2143: syntax error : missing ',' before ')' 100
Error 44 error C2143: syntax error : missing ',' before ')' 84
Error 48 error C2143: syntax error : missing ',' before ')' 82
Error 52 error C2143: syntax error : missing ',' before ')' 100
Error 17 error C2143: syntax error : missing ',' before ';' 25
Error 19 error C2143: syntax error : missing ',' before ';' 26
Error 21 error C2143: syntax error : missing ',' before ';' 27
Error 23 error C2143: syntax error : missing ',' before ';' 28
Error 25 error C2143: syntax error : missing ',' before ';' 30
Error 27 error C2143: syntax error : missing ',' before ';' 31
Error 29 error C2143: syntax error : missing ',' before ';' 32
Error 31 error C2143: syntax error : missing ',' before ';' 33
Error 7 error C2143: syntax error : missing ';' before '{' 32
Error 15 error C2143: syntax error : missing ';' before '{' 10
Error 32 error C2143: syntax error : missing ';' before '{' 36
Error 35 error C2143: syntax error : missing ';' before '{' 27
Error 45 error C2143: syntax error : missing ';' before '{' 32
Error 54 error C2143: syntax error : missing ';' before '{' 34
Error 57 error C2143: syntax error : missing ';' before '{' 48
Error 60 error C2143: syntax error : missing ';' before '{' 61
Error 3 error C2143: syntax error : missing ';' before '}' 82
Error 11 error C2143: syntax error : missing ';' before '}' 98
Error 33 error C2143: syntax error : missing ';' before '}' 42
Error 34 error C2143: syntax error : missing ';' before '}' 45
Error 36 error C2143: syntax error : missing ';' before '}' 83
Error 37 error C2143: syntax error : missing ';' before '}' 85
Error 41 error C2143: syntax error : missing ';' before '}' 82
Error 49 error C2143: syntax error : missing ';' before '}' 98
Error 55 error C2143: syntax error : missing ';' before '}' 43
Error 58 error C2143: syntax error : missing ';' before '}' 57
Error 61 error C2143: syntax error : missing ';' before '}' 69
Error 67 error C2143: syntax error : missing ';' before '}' 42
Error 5 error C2275: 'Faction' : illegal use of this type as an expression 84
Error 43 error C2275: 'Faction' : illegal use of this type as an expression 84
Error 9 error C2275: 'std::ofstream' : illegal use of this type as an expression 82
Error 47 error C2275: 'std::ofstream' : illegal use of this type as an expression 82
Error 53 error C2653: 'Socialite' : is not a class or namespace name 33
Error 56 error C2653: 'Socialite' : is not a class or namespace name 46
Error 59 error C2653: 'Socialite' : is not a class or namespace name 60
Error 62 error C2653: 'Socialite' : is not a class or namespace name 72
Probably a missing ; after the closing } of a class / struct. Could you post some code?
UPDATE: The code compiles now on my gcc. The problem I found is that you have a circular dependency between your classes. So solve this, forward declare some of them in the headers. I added class Faction; before class Socialite in Socialite.h and class Socialite; before class Faction in Faction.h.
Unexpected end of file is usually that you are missing a closing "something", such as a bracket } or parenthesis )
It's either a missing #endif or a ; at the end of a type definition or possibly a missing } at the end of a function.
Start with the first error reported. Often it's the cause of a lot of the subsequent problems because the first error causes the parser to be out of sync with the rest of the code.
In C++, long cascades of errors are often caused by an undeclared type (did you forget an include file?) or by a missing ; after a class or struct definition.
Consider:
Foobar fb; // Declare an instance of Foobar.
If Foobar hasn't been declared yet (perhaps because you forgot to include "foobar.h"), then the compiler might think you're trying to declare a variable named Foobar with a default type of int. From there, it sees the fb and gets all confused.
Or consider:
struct Foobar {
int x;
int y;
}
int blah = 0;
Without the ; after the struct definition, the parser thinks you're trying to declare an instance of Foobar named int, which isn't allowed since int is a reserved keyword. And everything after that looks like gobbledegook to the compiler.
One trick is to temporarily #if 0-out all the code after the line with the first reported error, as that will reduce the noise until you isolate the original problem.
If you look at the "Error List" window (View > Error List) it can be really hard to figure out where the errors originate. Luckily, there's another way:
Open the "Output" window (Debug > Windows > Output)
Compile and build
Start at the top of the "Output" window and work your way down the compiler/linker output text until you come to the first line that says "error"
This will usually lead you right to the problem.
I have some errors in my header file, which I don't know how to fix because I am fairly new to C++.
Here is the code of the header file:
#pragma once
typedef unsigned int uint;
class DCEncryption
{
public:
static char* manageData(char*, char*, uint);
private:
static int max(int, int);
static uint leftRotate(uint, int);
};
And here are the errors:
- dcencryption.h(12): error C2062: type 'int' unexpected
- dcencryption.h(12): error C2334: unexpected token(s) preceding ':'; skipping apparent function body
- dcencryption.h(12): error C2760: syntax error : expected '{' not ';'
- dcencryption.h(13): error C2144: syntax error : 'uint' should be preceded by '}'
- dcencryption.h(13): error C2143: syntax error : missing ')' before ';'
- dcencryption.h(13): error C2059: syntax error : ')'
- dcencryption.h(13): error C2143: syntax error : missing ';' before ')'
- dcencryption.h(13): error C2238: unexpected token(s) preceding ';'
You are probably on Windows and you have included windef.h directly or indirectly (through windows.h, maybe) from your main .cpp file before including the shown file.
It so happens that max is a macro defined in windef.h that does not expand nicely in your context.
This can quite easily happen on some other platforms as well.
Im trying to compile SDL_mixer 2 with SDL2 checked out the latest code from :
http://hg.libsdl.org/SDL_mixer
also compiled with no problem SDL2 and SDL_image.
when compiling SDL_mixer im getting the compilation errors :
1>Compiling...
1>dynamic_mp3.c
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(39) : error C2143: syntax error : missing ')' before '*'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(39) : error C2143: syntax error : missing '{' before '*'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(39) : error C2143: syntax error : missing ';' before '*'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(39) : error C2371: 'SDL_Rect' : redefinition; different basic types
1> d:\cpp\2d\love\lov8\lib\sdl\include\sdl_rect.h(69) : see declaration of 'SDL_Rect'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(39) : error C2143: syntax error : missing ';' before '*'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(39) : error C2371: 'SMPEG_FilterInfo' : redefinition; different basic types
1> d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(33) : see declaration of 'SMPEG_FilterInfo'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(39) : error C2143: syntax error : missing ';' before '*'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(39) : error C2059: syntax error : 'type'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(39) : error C2059: syntax error : ')'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(46) : error C2061: syntax error : identifier 'SMPEG_FilterCallback'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(48) : error C2059: syntax error : '}'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(56) : error C2143: syntax error : missing '{' before '*'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(59) : error C2143: syntax error : missing '{' before '*'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(62) : error C2143: syntax error : missing '{' before '*'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\smpeg.h(180) : error C2143: syntax error : missing '{' before '*'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\smpeg.h(180) : error C2143: syntax error : missing ')' before '*'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\smpeg.h(180) : error C2081: 'SMPEG_Filter' : name in formal parameter list illegal
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\smpeg.h(180) : error C2143: syntax error : missing '{' before '*'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\smpeg.h(180) : error C2059: syntax error : ')'
1>mixer.c
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(39) : error C2143: syntax error : missing ')' before '*'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(39) : error C2143: syntax error : missing '{' before '*'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(39) : error C2143: syntax error : missing ';' before '*'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(39) : error C2371: 'SDL_Rect' : redefinition; different basic types
1> d:\cpp\2d\love\lov8\lib\sdl\include\sdl_rect.h(69) : see declaration of 'SDL_Rect'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(39) : error C2143: syntax error : missing ';' before '*'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(39) : error C2371: 'SMPEG_FilterInfo' : redefinition; different basic types
1> d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(33) : see declaration of 'SMPEG_FilterInfo'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(39) : error C2143: syntax error : missing ';' before '*'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(39) : error C2059: syntax error : 'type'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(39) : error C2059: syntax error : ')'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(46) : error C2061: syntax error : identifier 'SMPEG_FilterCallback'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(48) : error C2059: syntax error : '}'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(56) : error C2143: syntax error : missing '{' before '*'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(59) : error C2143: syntax error : missing '{' before '*'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(62) : error C2143: syntax error : missing '{' before '*'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\smpeg.h(180) : error C2143: syntax error : missing '{' before '*'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\smpeg.h(180) : error C2143: syntax error : missing ')' before '*'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\smpeg.h(180) : error C2081: 'SMPEG_Filter' : name in formal parameter list illegal
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\smpeg.h(180) : error C2143: syntax error : missing '{' before '*'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\smpeg.h(180) : error C2059: syntax error : ')'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\mixer.c(129) : warning C4090: 'function' : different 'const' qualifiers
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\mixer.c(1145) : warning C4090: 'function' : different 'const' qualifiers
1>music.c
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(39) : error C2143: syntax error : missing ')' before '*'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(39) : error C2143: syntax error : missing '{' before '*'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(39) : error C2143: syntax error : missing ';' before '*'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(39) : error C2371: 'SDL_Rect' : redefinition; different basic types
1> d:\cpp\2d\love\lov8\lib\sdl\include\sdl_rect.h(69) : see declaration of 'SDL_Rect'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(39) : error C2143: syntax error : missing ';' before '*'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(39) : error C2371: 'SMPEG_FilterInfo' : redefinition; different basic types
1> d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(33) : see declaration of 'SMPEG_FilterInfo'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(39) : error C2143: syntax error : missing ';' before '*'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(39) : error C2059: syntax error : 'type'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(39) : error C2059: syntax error : ')'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(46) : error C2061: syntax error : identifier 'SMPEG_FilterCallback'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(48) : error C2059: syntax error : '}'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(56) : error C2143: syntax error : missing '{' before '*'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(59) : error C2143: syntax error : missing '{' before '*'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\mpegfilter.h(62) : error C2143: syntax error : missing '{' before '*'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\smpeg.h(180) : error C2143: syntax error : missing '{' before '*'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\smpeg.h(180) : error C2143: syntax error : missing ')' before '*'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\smpeg.h(180) : error C2081: 'SMPEG_Filter' : name in formal parameter list illegal
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\smpeg.h(180) : error C2143: syntax error : missing '{' before '*'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\visualc\external\include\smpeg.h(180) : error C2059: syntax error : ')'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\music.c(166) : warning C4090: 'function' : different 'const' qualifiers
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\music.c(625) : warning C4047: 'return' : 'Mix_Music *' differs in levels of indirection from 'int'
1>d:\cpp\2d\sdl2.0\sdl-2.0\sdl_mixer\music.c(1529) : warning C4090: 'function' : different 'const' qualifiers
any one has any idea ?
I think you can remove the MP3_MUSIC preprocessor macro or include smpeg in you search path.
Take a look at the PreProcessor Definitions.
Remove these
MOD_MUSIC
MOD_DYNAMIC=\"libmikmod-2.dll\"
OGG_MUSIC
OGG_DYNAMIC=\"libvorbisfile-3.dll\"
FLAC_MUSIC
FLAC_DYNAMIC=\"libFLAC-8.dll\"
MP3_MUSIC
MP3_DYNAMIC=\"smpeg.dll\"
If you want to use any of those file types in your audio, you need to get those .dll files as well. I would recommend compiling those libraries statically instead of dynamically to make thing more cross-platform compatible.
Because someone in our group hates exceptions (let's not discuss that here), we tend to use error-checking macros in our C++ projects. I have encountered an odd compilation failure when using a templated function with two type parameters. There are a few errors (below), but I think the root cause is a warning:
warning C4002: too many actual parameters for macro 'BOOL_CHECK_BOOL_RETURN'
Probably best explained in code:
#include "stdafx.h"
template<class A, class B>
bool DoubleTemplated(B & value)
{
return true;
}
template<class A>
bool SingleTemplated(A & value)
{
return true;
}
bool NotTemplated(bool & value)
{
return true;
}
#define BOOL_CHECK_BOOL_RETURN(expr) \
do \
{ \
bool __b = (expr); \
if (!__b) \
{ \
return false; \
} \
} while (false) \
bool call()
{
bool thing = true;
// BOOL_CHECK_BOOL_RETURN(DoubleTemplated<int, bool>(thing));
// Above line doesn't compile.
BOOL_CHECK_BOOL_RETURN((DoubleTemplated<int, bool>(thing)));
// Above line compiles just fine.
bool temp = DoubleTemplated<int, bool>(thing);
// Above line compiles just fine.
BOOL_CHECK_BOOL_RETURN(SingleTemplated<bool>(thing));
BOOL_CHECK_BOOL_RETURN(NotTemplated(thing));
return true;
}
int _tmain(int argc, _TCHAR* argv[])
{
call();
return 0;
}
Here are the errors, when the offending line is not commented out:
1>------ Build started: Project: test, Configuration: Debug Win32 ------
1>Compiling...
1>test.cpp
1>c:\junk\temp\test\test\test.cpp(38) : warning C4002: too many actual parameters for macro 'BOOL_CHECK_BOOL_RETURN'
1>c:\junk\temp\test\test\test.cpp(38) : error C2143: syntax error : missing ',' before ')'
1>c:\junk\temp\test\test\test.cpp(38) : error C2143: syntax error : missing ';' before '{'
1>c:\junk\temp\test\test\test.cpp(41) : error C2143: syntax error : missing ';' before '{'
1>c:\junk\temp\test\test\test.cpp(48) : error C2143: syntax error : missing ';' before '{'
1>c:\junk\temp\test\test\test.cpp(49) : error C2143: syntax error : missing ';' before '{'
1>c:\junk\temp\test\test\test.cpp(52) : error C2143: syntax error : missing ';' before '}'
1>c:\junk\temp\test\test\test.cpp(54) : error C2065: 'argv' : undeclared identifier
1>c:\junk\temp\test\test\test.cpp(54) : error C2059: syntax error : ']'
1>c:\junk\temp\test\test\test.cpp(55) : error C2143: syntax error : missing ';' before '{'
1>c:\junk\temp\test\test\test.cpp(58) : error C2143: syntax error : missing ';' before '}'
1>c:\junk\temp\test\test\test.cpp(60) : error C2143: syntax error : missing ';' before '}'
1>c:\junk\temp\test\test\test.cpp(60) : fatal error C1004: unexpected end-of-file found
1>Build log was saved at "file://c:\junk\temp\test\test\Debug\BuildLog.htm"
1>test - 12 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Any ideas? Thanks!
The preprocessor has no understanding of C++! It simply performs lexical substitutions.
When you declare a multi-argument macro, the arguments are separated by a comma. Since you have a comma in your macro invocation, you're calling the macro with multiple parameters, despite it being declared to only take one argument.
Parentheses are understood by the PP as forming a token group, so everything inside a set of parentheses is one big token.
Macros are unaware of the language, and work only with lexical tokens. A comma separates arguemnts for a macro, thus the following code attemps to 'invoke' the macro with two arguments:
BOOL_CHECK_BOOL_RETURN(DoubleTemplated<int, bool>(thing));
DoubleTemplated<int and bool>(thing). That's the warning you are seeing, and cause of the other errors as well. The following is the correct way to protect against , in template arguments list:
BOOL_CHECK_BOOL_RETURN((DoubleTemplated<int, bool>(thing)));
In the line that doesn't compile, that comma is interpreted by the preprocessor as a delimiter of the macro arguments.
In the C99 standard (I haven't got the C++ standard to hand, but it will be very similar), we see the following in section 6.10.3:
The sequence of preprocessing tokens bounded by the outside-most
matching parentheses forms the list of arguments for the function-like
macro. The individual arguments within the list are separated by comma
preprocessing tokens, but comma preprocessing tokens between matching
inner parentheses do not separate arguments.
So that's why your second macro instantiation works.
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 11 years ago.
Im writing a project in C with visual studio that contains these files:
multiThreadServer.cpp
myLib.cpp
myLib.h
The 1st (multiThreadServer.cpp) includes these
#include <WinSock2.h>
#include <Windows.h>
#include <stdio.h>
#include "myLib.h"
2nd (myLib.cpp) these
#include <WinSock2.h>
#include <stdio.h>
#include "myLib.h"
3nd (myLib.h) includes nothing
In .h file i have these functions defined:
// Starts up the server.
INT start_server(const unsigned short port);
// Accept Connections.
BOOL accept_connections();
// Accept Client.
BOOL AcceptClient(PCLIENT current_client);
// Receiver Function for the thread.
DWORD WINAPI Receiver(LPVOID lpParam);
// Receive data from client.
BOOL recv_data(PCLIENT current_client, char *buffer, int size);
// End server.
VOID end_server();
// Send data.
BOOL send_data(PCLIENT current_client, char *buffer, int size);
// Disconnect Client.
VOID disconnect_client(PCLIENT current_client);
// Send Data to all clients.
BOOL send_data_to_all(char *message);
Here is part of myLib.cpp:
typedef struct _client{
SOCKADDR_IN address; // internal data structure regarding this client
SOCKET socket; // this clients socket
BOOL connected; // is this client connected
char IP[20]; // this clients IP address
int address_length; // internal data structure regarding this client
} CLIENT, *PCLIENT;
Now, when im going to compile the whole project these annoying syntax errors returned:
1> myLib.cpp
\mylib.h(8): error C2146: syntax error : missing ')' before identifier 'current_client'
\mylib.h(8): error C2061: syntax error : identifier 'current_client'
\mylib.h(8): error C2059: syntax error : ';'
\mylib.h(8): error C2059: syntax error : ')'
\mylib.h(14): error C2146: syntax error : missing ')' before identifier 'current_client'
\mylib.h(14): error C2061: syntax error : identifier 'current_client'
\mylib.h(14): error C2059: syntax error : ';'
\mylib.h(14): error C2059: syntax error : ','
\mylib.h(14): error C2059: syntax error : ')'
\mylib.h(20): error C2146: syntax error : missing ')' before identifier 'current_client'
\mylib.h(20): error C2061: syntax error : identifier 'current_client'
\mylib.h(20): error C2059: syntax error : ';'
\mylib.h(20): error C2059: syntax error : ','
\mylib.h(20): error C2059: syntax error : ')'
\mylib.h(23): error C2146: syntax error : missing ')' before identifier 'current_client'
\mylib.h(23): error C2061: syntax error : identifier 'current_client'
\mylib.h(23): error C2059: syntax error : ';'
\mylib.h(23): error C2059: syntax error : ')'
\mylib.cpp(103): warning C4013: 'AcceptClient' undefined; assuming extern returning int
\mylib.cpp(168): warning C4013: 'recv_data' undefined; assuming extern returning int
\mylib.cpp(188): warning C4013: 'send_data' undefined; assuming extern returning int
\mylib.cpp(189): warning C4013: 'disconnect_client' undefined; assuming extern returning int
\mylib.cpp(270): error C2371: 'disconnect_client' : redefinition; different basic types
1> multiThreadServer.cpp
\mylib.h(8): error C2146: syntax error : missing ')' before identifier 'current_client'
1\mylib.h(8): error C2061: syntax error : identifier 'current_client'
\mylib.h(8): error C2059: syntax error : ';'
\mylib.h(8): error C2059: syntax error : ')'
\mylib.h(14): error C2146: syntax error : missing ')' before identifier 'current_client'
\mylib.h(14): error C2061: syntax error : identifier 'current_client'
\mylib.h(14): error C2059: syntax error : ';'
\mylib.h(14): error C2059: syntax error : ','
\mylib.h(14): error C2059: syntax error : ')'
\mylib.h(20): error C2146: syntax error : missing ')' before identifier 'current_client'
\mylib.h(20): error C2061: syntax error : identifier 'current_client'
\mylib.h(20): error C2059: syntax error : ';'
\mylib.h(20): error C2059: syntax error : ','
\mylib.h(20): error C2059: syntax error : ')'
\mylib.h(23): error C2146: syntax error : missing ')' before identifier 'current_client'
\mylib.h(23): error C2061: syntax error : identifier 'current_client'
\mylib.h(23): error C2059: syntax error : ';'
\mylib.h(23): error C2059: syntax error : ')'
I m searching 1.30 hour now on net but i cannot find a way to fix it.
What the problem could be ?
Alternatively to what's suggested here, you fix the problem in the header file without actually moving the definition of PCLIENT into the header:
...
struct _client;
...
// Accept Client.
BOOL AcceptClient(struct _client* current_client);
...
// Receive data from client.
BOOL recv_data(struct _client* current_client, char *buffer, int size);
...
// Send data.
BOOL send_data(struct _client* current_client, char *buffer, int size);
// Disconnect Client.
VOID disconnect_client(struct _client* current_client);
...