6

I have some Microsoft code (XLCALL.CPP) which I am trying to compile with CodeBlocks/MinGW.
At this line I get a compile time error:

__forceinline void FetchExcel12EntryPt(void)

This is the error message I get:

XLCALL.CPP|36|error: expected constructor, destructor, or type conversion before 'void'

This error is expected, because __forceinline is a Microsoft specific addition to the language, not recognized by GCC.

So, to get things compile, I try to add thiese defines in CodeBlocks (Project Build Options/Compiler Settings/#defines):

#define __forceinline inline
#define __forceinline 

However I still get the same error.

If in the dialog I do not specify the #define preprocessor command (i.e.: __forceinline inline), this is what I get:

XLCALL.CPP|36|error: expected unqualified-id before numeric constant

Is there a way to compile such a piece of code, without using Visual C++?

pnuts
  • 58,317
  • 11
  • 87
  • 139
Pietro M
  • 1,905
  • 3
  • 20
  • 24

1 Answers1

12

The syntax is __forceinline=inline, as you've noted in the comments, because these settings get turned into -D options to GCC.

Note that inline is a strong hint to GCC that the function should be inlined, but does not guarantee it. The GCC equivalent of __forceinline is the always_inline attribute - e.g. this code:

#define __forceinline __attribute__((always_inline))

or equivalently this setting:

__forceinline="__attribute__((always_inline))"

(But this might well be unnecessary: if there was some particularly good reason for forcing this function to be inlined when compiling with MSVC, that reason may well not be valid when using a completely different compiler!)

Matthew Slattery
  • 45,290
  • 8
  • 103
  • 119
  • Though it's a correct answer to the original question, one may note that using __attribute(always_inline) may litter you with compiler warnings like "warning: always_inline function might not be inlinable [-Wattributes]" – Yogurt Jul 01 '20 at 17:37
  • @Yogurt You might want to use `#define __forceinline inline __attribute__((always_inline))` in order to remove those warnings. – madmann91 Aug 30 '22 at 09:51