Question

I'm trying to compile a little project that includes windows.h using the clang compiler. Unfortunately, clang produces some errors I'm not able to resolve. What's causing these errors? Does clang not support all required features, am I missing something?

In file included from C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/wind
ows.h:155:
In file included from C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/wind
ef.h:177:
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/winnt.h(12857) :  warning:

  expression result unused [-Wunused-value]
UNREFERENCED_PARAMETER(CallbackEnviron);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/winnt.h:12857:28: note: in
stantiated from:
UNREFERENCED_PARAMETER(CallbackEnviron);
                       ^~~~~~~~~~~~~~~

In file included from C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/wind
ows.h:156:
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/winbase.h(2326) :  error:

  invalid operands to binary expression ('LONGLONG' (aka 'double') and
  'LONGLONG')
                                      Old & Value,
                                      ~~~ ^ ~~~~~
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/winbase.h(2327) :  error:

  expected ')'
                                      Old) != Old);
                                           ^
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/winbase.h(2325) :  note:
  to match this '('
} while (InterlockedCompareExchange64(Destination,
        ^
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/winbase.h(2344) :  error:

  invalid operands to binary expression ('LONGLONG' (aka 'double') and
  'LONGLONG')
                                      Old | Value,
                                      ~~~ ^ ~~~~~
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/winbase.h(2345) :  error:

  expected ')'
                                      Old) != Old);
                                           ^
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/winbase.h(2343) :  note:
  to match this '('
} while (InterlockedCompareExchange64(Destination,
        ^
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/winbase.h(2362) :  error:

  invalid operands to binary expression ('LONGLONG' (aka 'double') and
  'LONGLONG')
                                      Old ^ Value,
                                      ~~~ ^ ~~~~~
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/winbase.h(2363) :  error:

  expected ')'
                                      Old) != Old);
                                           ^
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/winbase.h(2361) :  note:
  to match this '('
} while (InterlockedCompareExchange64(Destination,
        ^

...and a lot more...
Was it helpful?

Solution

You probably need to define a clang-compatible version of the UNREFERENCED_PARAMETER macro. Something like this should help you on the way: https://web.archive.org/web/20130425151054/http://sourcefrog.net/weblog/software/languages/C/unused.html

Also, it seems the type LONGLONG is defined as double for clang, and you can't do binary arithmetic (and, or, not etc) on floats. You need to make sure this is typedefed as a proper integer type.

Depending a bit on how windows.h, winbase.h and winnt.h is structured you may be able to make your own wrapper that gets the right defines in place to make this pass. Otherwise, try to find a gcc-compatible version of windows.h, and use that. Clang should be compatible with it.

Good luck!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top