[CM] s7_complex does not compile for MSVC
Da Shen
da at liii.pro
Tue Nov 19 21:28:47 PST 2024
> Is there some way in MSVC to ask for C and not C++?
see https://learn.microsoft.com/en-us/cpp/build/reference/tc-tp-tc-tp-specify-source-file-type?view=msvc-170 <https://learn.microsoft.com/en-us/cpp/build/reference/tc-tp-tc-tp-specify-source-file-type?view=msvc-170 >
Because I'm not invoking MSVC directly via command line, I didn't get it work with xmake. And I tried to rename s7.c to s7.cpp, and found the C source code in s7.c will produce error when it is regarded as C++.
## My final solution is:
Patch s7.h in this way:
#if (__TINYC__ || (__clang__ && __cplusplus) || _MSC_V)
typedef double s7_complex;
#else
#if (__cplusplus || _MSC_VER)
#include <complex>
typedef std::complex<s7_double> s7_complex;
#else
#include <complex.h>
typedef double complex s7_complex;
#endif
#endif
Just use double for s7_complex and define HAVE_COMPLEX_NUMBERS=0.
## What I have tried:
And I tried to solve the problem of `typedef double complex s7_complex;` by replacing it with `typedef _Dcomplex s7_complex` but failed.
see https://github.com/microsoft/STL/issues/3280 <https://github.com/microsoft/STL/issues/3280 >
To include complex.h, one must guard it with _CRT_USE_C_COMPLEX_H, if one decide to make it work, one must solve the issues in s7.c like:
1. define CMPLX for MSVC
2. Solve the issues for futher incompatibility
## Suggested way to make it work
1. Assumming HAVE_COMPLEX_NUMBER=0 , when we are using a C compiler
2. Assumming HAVE_COMPLEX_NUMBER=1, when we are using a C++ compiler
For 1, because it is a nightmare to make the C code work for Windows and *nix.
For 2, because it is much easier to make the C++ code work for Windows and *nix.
And for 2, we might need to make sure that when we rename s7.c to s7.cpp, it should compile in MSVC.
(sorry for sending this email twice, because for the first time, it was sent to Bill privately. To make it public, I'm sending it to the mail list this time)
------------------------------------------------------------------
From:bil <bil at ccrma.Stanford.EDU>
Send Time:2024 Nov. 19 (Tue.) 23:03
To:"沈达"<da at liii.pro>
Cc:cmdist<cmdist at ccrma.Stanford.EDU>
Subject:Re: [CM] s7_complex does not compile for MSVC
Thanks for the info about MSVC. I think I could get
further in clang++, assuming C++11, with
using s7_complex = std::complex<double>;
but there were still endless complaints (mostly about
missing casts). In clang++, the first warning is
clang: warning: treating 'c' input as 'c++' when in C++ mode, this
behavior is deprecated
which makes me think the C++ community has decided to
cut its ties to C. I'll go back and poke at this,
but it feels like a hopeless situation. Is there
some way in MSVC to ask for C and not C++?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cm-mail.stanford.edu/pipermail/cmdist/attachments/20241120/76ac1fd9/attachment-0001.html>
More information about the Cmdist
mailing list