tags:

views:

164

answers:

3
wprintf(L"Selecting Audio Input Device: %s\n", 
                            varName.bstrVal);
if(0 == wcscmp(varName.bstrVal, L"IP Camera [JPEG/MJPEG]"))
{
    ...
}

hr = CoCreateInstance(CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER,
                        IID_IBaseFilter, (void **)&pGrabberF);

The above is from a .cpp file ,but as you see its content is quite c-style.

Will you call it a c or c++ project?

+4  A: 

It simply depends how you compile it.

Some code will compile as both, it's considered C++ code if it gets compiled by a C++ compiler.

C is NOT an exact subset of C++ by the way.

Often you can deduce with a fast glance simply by the file's extension, although it's possible to put C code in a .cc extension or .cpp extension and you can also put C++ code in a .c extension, but that would be pretty rare.

Brian R. Bondy
It seems to me visual studio uses the same compiler for c and c++,doesn't it?
COMer
@COMer: For the most part. If you use .c though it will compile as C, and will allow things like implicit casts from `void*`.
Billy ONeal
I added one extra line in my post,what about now?
COMer
@COMer: Yes you can still call it a C++ project. The Win32 APIs are built to work with C and you can also use C++.
Brian R. Bondy
Do you mean all Win32 APIs can be used in both c and c++?
COMer
yes that is correct.
Brian R. Bondy
VC++ is hardly a C compiler. It's awful. However I do believe that C++03 "merged" in C89, and this is what VC++ supports. It's a real shame that your first experience with C is through Windows and MSVC.
Matt Joiner
A: 

I'd say it depends on linkage. If it's a library intended to be C linkable, it's C. If it requires C++ to link with, it's C++. If it provides both options, it's both.

If however it's not a library, and it requires a C++ compiler to build, it's a C++ project.

Matt Joiner
I added one extra line in my post,what about now?
COMer
+1  A: 

I'd call it a C project because I wouldn't be caught dead using C-style string comparison via raw pointer in C++. Exceptions or other stuff would annihilate that code. A correct solution would be to change bstrVal into a BSTR class, which has an operator== overload for wchar_t*.

DeadMG
BSTR is not a class, it's a type (OLECHAR*). Did you mean _bstr_t or CComBSTR?
Steve Townsend
That's why I suggested CHANGE it into an RAII self-releasing operator-overloaded class.
DeadMG