tags:

views:

261

answers:

4

I'm trying to rebuild someone's old C++ project using Dev-C++ (version 4.9.9.2) and the standard compiler that it comes with (I think g++ using MinGW) under Windows XP Pro SP3 32-bit. In one of the files strsafe.h is included and when I try to compile, I get this error:

expected primary-expression before ',' token

The lines of code that the error points to are in strsafe.h (a Microsoft(?) library header file) all look something like this:

hr = StringGetsExWorkerA(pszDest, cchDest, cbDest, NULL, NULL, 0);

There are 2 "expected primary-expression" errors for each of these lines. I found this forum thread which suggests that the NULL value is not properly recognized and suggests that I include <cstddef> before strsafe.h. I did that and it doesn't work. Also, it appears that NULL is in fact defined, because when I do '#define NULL 0' before including strsafe.h I get an error telling me that I'm redefining it there.

I'm sorry I can't provide any more details, but the code to reproduce this error is simply '#include <strsafe.h>', so I don't really know what else to say. Does anyone have any idea what might be going on and how I can fix this?

Thanks!

(I already tried downloading the latest version of the Microsoft Platform SDK so I have an up-to-date version of strsafe.h)

A: 

I wonder what NULL is defined as? Maybe it's not 0, it could be anything (though it would be really odd if someone defined NULL as something other than 0).

Try the following and see if it works.

#undef NULL
#define NULL 0
Glen
In C, NULL is usually defined as (void*)0, though it is a straight 0 in C++.
Tyler McHenry
This actually worked. (now I have other problems, but this issue is resolved using these two lines of code)
Jordi
@Tyler, in C or C++ there's no such thing as NULL. some/most compilers may define it as (void*)0 or 0 but there's absolutely nothing stopping any header / library / thirdparty code / compiler defining NULL as something else. NULL isn't part of the standard, so you shouldn't use it
Glen
@Glen - macro NULL is standard - it's defined in `<stddef.h>` (or `<cstddef>` or other headers). The real fix is to simply include `<stddef.h>`. If some bonehead is defining it to be something else, that should be fixed.
Michael Burr
A: 

My initial thoughts would be that at least one of those identifiers has not yet declared.

Try the following:

  • Check your compiler documentation for the option to generate preprocessed output (and generate it)
  • Locate this line the preprocessed output and
  • For each identifier in turn, search backwards to find its declaration

You may find that the identifiers are not declared, or that one of them is declared as a type rather than an object.

Richard Corden
A: 

Looking through the strsafe.h file it seems like this function is an internal one (it's surrounded by #ifndef STRSAFE_LIB_IMPL .... #endif blocks) and it's wrapped around functions like StringCbGetsExA or StringCbGetsExA. Shouldn't you use those instead?

Blindy
It happens to almost all functions, and besides, I don't even think I'm calling that function. Just including the library causes compilation to fail.
Jordi
A: 

I think that you may have a mix of SDK headers in your include path. Check your include path; gcc's "-H" option would help you find out what mixing (if any) is happening.

Michael Burr
I'm sorry, but I don't really know how. I'm using the Dev-Cpp environment's compile-button and I don't know what other parameters gcc gets called with. Besides, I would probably not really know what to do with the output.
Jordi
I don't know anything about Dev-Cpp so I can't help with the "how". But if and when you get the information, in the worst case edit it into your question and someone here might be able to help.
Michael Burr