Dark Bit Factory & Gravity

PROGRAMMING => C / C++ /C# => Topic started by: Raizor on June 08, 2011

Title: Problem mixing C++ and C
Post by: Raizor on June 08, 2011
I've been using iq's 64k C++ framework as a base for my demo stuff. I've hit a weird issue that I don't quite understand.

In my code, I'm using C++ to create objects:

blah* myBlah = new blah();

This works fine until I include the minifmod source files (which are all C and have a .c extension). As soon as they're included, it starts complaining about the code for new() and delete() in iq's framework:

inline void * __cdecl  operator new( size_t size ) { return(msys_mallocAlloc((uint32)size)); }
inline void   __cdecl  operator delete( void *ptr ) { msys_mallocFree(ptr); }

I get a load of compiler errors such as these:

Warning   1   Command line warning D9035 : option 'QIfist' has been deprecated and will be removed in a future release   cl   framework64k
Error   2   error C2054: expected '(' to follow 'inline'   e:\democoding\64k_orig - copy\src\sys\msys_malloc.h   24   framework64k
Warning   3   warning C4229: anachronism used : modifiers on data are ignored   e:\democoding\64k_orig - copy\src\sys\msys_malloc.h   24   framework64k
Error   4   error C2085: 'operator' : not in formal parameter list   e:\democoding\64k_orig - copy\src\sys\msys_malloc.h   24   framework64k
Error   5   error C2146: syntax error : missing ',' before identifier 'new'   e:\democoding\64k_orig - copy\src\sys\msys_malloc.h   24   framework64k
Error   6   error C2143: syntax error : missing ';' before '('   e:\democoding\64k_orig - copy\src\sys\msys_malloc.h   24   framework64k
Error   7   error C2059: syntax error : ')'   e:\democoding\64k_orig - copy\src\sys\msys_malloc.h   24   framework64k

... there are about 40 of these errors

I've been hunting around for clues and came across some stuff mentioning __cdecl  and __fastcall. Not sure if that's a red herring though and unrelated to this issue.

If anyone knows what I'm doing wrong or can point me in the right direction, I'd be very grateful.

Thanks,

Raizor


Title: Re: Problem mixing C++ and C
Post by: Jim on June 09, 2011
Seems like something in the C code is trying to #include msys_malloc.h and it doesn't understand the C++ code in there.

Jim
Title: Re: Problem mixing C++ and C
Post by: Raizor on June 09, 2011
Doh! That's probably it Jim. Many thanks, I'll give that a try.

EDIT: Yep, that's sorted it Jim. Thanks again K++ :)