24

I'm looking through the Windows 8.1 SDK and in UnknownBase.h I'm seeing things like

typedef interface IUnknown IUnknown;

I've never seen this interface keyword before. Note that this is very definitely a .h header, processed by cl.exe. It's not IDL file, and it's not processed by midl.exe.

I found this online: http://msdn.microsoft.com/en-us/library/50h7kwtb.aspx

But __interface is not the same as interface

Can anyone clue me in here?

fieldtensor
  • 3,972
  • 4
  • 27
  • 43
  • 1
    Is there a `#define interface` somewhere? It's sure not natively a C++ keyword, but the preprocessor could make it look like one. – Greg Hewgill Aug 11 '14 at 00:09
  • http://msdn.microsoft.com/en-us/library/windows/desktop/ms680509(v=vs.85).aspx – BLUEPIXY Aug 11 '14 at 00:27
  • 1
    Just right-click "interface" in the editor and select Go To Definition. __interface is a non-standard keyword, [well documented in MSDN](http://msdn.microsoft.com/en-us/library/50h7kwtb.aspx). As you can tell, it provides a lot more guarantees than *struct* does. The concept is pretty big in many languages, massive in COM. It can be expressed in C++ as well without language extensions, just a lot more error prone. A compiler can tell you when you made a mistake, but only if it understands the concept. – Hans Passant Aug 11 '14 at 00:38
  • 1
    @HansPassant Oddly, when I right clicked on `interface` in visual studio the option for `Go To Definition` was grayed out (which is what prompted my stack overflow post in the first place). But as I describe in a comment below to MarcoA, a findstr did the trick. It's odd that that visual studio can't find it though. – fieldtensor Aug 11 '14 at 01:15

1 Answers1

20

Microsoft has some compiler-specific extensions like the one you linked but interface shouldn't be a native C++ compiler-specific keyword but rather a define which substitutes something (in BaseTyps.h it used to be defined as follows)

# define interface  struct

Link here

If you want to verify this do a grep for such a definition and you should find something similar.


References: http://social.msdn.microsoft.com/forums/vstudio/en-US/06bf1dea-1d20-4ec3-b9a1-3d673d7fcd8d/what-is-the-interface-keyword-in-native-c

Marco A.
  • 43,032
  • 26
  • 132
  • 246
  • 4
    Wow, yep, that's it. I did a `findstr /s /i /c:"#define interface" *` from within `C:\Program Files (x86)\Windows Kits\8.1\Include`, and in `combaseapi.h` I found `#define interface struct` – fieldtensor Aug 11 '14 at 01:08