yeap
yeap

Reputation: 307

debug error in visual studio

can somebody please explain me what am I doing wrong here, I receive an error unexpected end of file and also missing function header, thanks in advance

static char debug[256];

#define DBGPRINT(...)           {sprintf_s(debug, 256, __VA_ARGS__); OutputDebugStringA(debug);}

#define CHECK_READ(status, str) while(0){                                                                               \
                                    if(0 == status){                                                                    \           
                                        DBGPRINT("Message %s\n", str);                  \
                                        return 0;                                                                       \
                                    }                                                                                   \
                                }                                                                                       
int main(){

char* str = "hello world";
status = 0;
CHECK_READ(status, str);

return 0;
}

error:

Error line  7   error C2447: '{' : missing function header (old-style formal list?)
Error   line 11 error C2447: '{' : missing function header (old-style formal list?)
Error   line 15 error C2017: illegal escape sequence    
Error   line 19 fatal error C1004: unexpected end-of-file found 

Upvotes: 0

Views: 478

Answers (2)

john
john

Reputation: 87959

OK here's the real answer.

I copy and paste from your code above, and you have trailing whitespace on one of your macro definition lines

if(0 == status){               \  WHITESPACE HERE

For a blackslash to operate as a line continuation character, it must be the last character on the line, no whitespace afterwards. Now who knows if this is your actual problem, but with the whitespace I got the same errors as you, and without it I didn't.

Upvotes: 1

Vlad
Vlad

Reputation: 35584

You have an extra \ at the end of macro definition. So your int main(){ line is actually a part of the macro CHECK_READ :)


EDIT:
The variant without trailing \ compiles well on ideone: http://ideone.com/pddx0. I declared the status, as it's not declared in your code. (I commented out OutputDebugStringA and replaced sprintf_s with snprintf, as they both are Microsoft-specific and wouldn't compile on gcc.)

Upvotes: 1

Related Questions