From 8dc0c5a6999aaf4447b4ab6d7c02deecaec2df13 Mon Sep 17 00:00:00 2001 From: Sumeet Chhetri Date: Sun, 10 May 2020 19:56:21 +0530 Subject: [PATCH] cgen: C++ compiler support - Part 1 --- vlib/v/gen/cgen.v | 3 +++ vlib/v/gen/cheaders.v | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index c2e045b190..bacf844feb 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -2884,6 +2884,9 @@ fn (mut g Gen) comp_if_to_ifdef(name string, is_comptime_optional bool) string { 'msvc' { return '_MSC_VER' } + 'cplusplus' { + return '__cplusplus' + } // other: 'debug' { return '_VDEBUG' diff --git a/vlib/v/gen/cheaders.v b/vlib/v/gen/cheaders.v index 9a7e92a3e3..0c1e386ab2 100644 --- a/vlib/v/gen/cheaders.v +++ b/vlib/v/gen/cheaders.v @@ -65,8 +65,14 @@ const ( c_headers = ' // c_headers +typedef int (*qsort_callback_func)(const void*, const void*); #include // TODO remove all these includes, define all function signatures and types manually #include +#ifdef __cplusplus +#include +#define _MOV std::move +#include +#endif //#include "fns.h" #include @@ -370,11 +376,13 @@ typedef map map_int; typedef map map_string; typedef byte array_fixed_byte_300 [300]; typedef byte array_fixed_byte_400 [400]; +#ifndef __cplusplus #ifndef bool typedef int bool; #define true 1 #define false 0 #endif +#endif ' bare_c_headers = '