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?

COMer
  • 1,117
  • 4
  • 14
  • 24

3 Answers3

4

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.

Community
  • 1
  • 1
Brian R. Bondy
  • 339,232
  • 124
  • 596
  • 636
  • It seems to me visual studio uses the same compiler for c and c++,doesn't it? – COMer Sep 13 '10 at 13:57
  • @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 Sep 13 '10 at 13:59
  • I added one extra line in my post,what about now? – COMer Sep 13 '10 at 14:07
  • @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 Sep 13 '10 at 14:11
  • Do you mean all Win32 APIs can be used in both c and c++? – COMer Sep 13 '10 at 14:39
  • 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 Sep 14 '10 at 02:47
1

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*.

Puppy
  • 144,682
  • 38
  • 256
  • 465
0

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.

Update0

It's still a matter of linkage. The code you've given will compile under both C and C++.

Matt Joiner
  • 112,946
  • 110
  • 377
  • 526