2

I would like to bring forward an issue regarding MinGW 4.7.2 I first ran into the deadly issue caused by libstdc++-6.dll when I ventured in OpenCV. Luckily, I ran across a workaround here -> http://answers.opencv.org/question/3740/opencv-243-mingw-cannot-run-program/. It looked great, for a time.

Now I am trying to implement complex numbers. I try the following code

#include <iostream>
#include <complex.h>
using namespace std;

int main(int argc, char* argv[])
{
    float _Complex d = 2.0f + 2.0f*I;
    cout << "Testing Complex\t" << d;
    return 0;
}

It should run, by all means. I face no errors or warnings while linking. I use CodeBlocks as my preferred IDE in Windows. But, again, I am stymied. Here is the AppCrash report

Problem signature:
  Problem Event Name:   APPCRASH
  Application Name: complex.exe
  Application Version:  0.0.0.0
  Application Timestamp:    515d61f7
  Fault Module Name:    libstdc++-6.dll
  Fault Module Version: 0.0.0.0
  Fault Module Timestamp:   4ed82a4d
  Exception Code:   c0000005
  Exception Offset: 000462bc
  OS Version:   6.1.7600.2.0.0.256.1
  Locale ID:    1033
  Additional Information 1: 0a9e
  Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
  Additional Information 3: 0a9e
  Additional Information 4: 0a9e372d3b4ad19135b953a78882e789

Yet amazingly, How to work with complex numbers in C? provides a perfectly working C code!

#include <stdio.h>      /* Standard Library of Input and Output */
#include <complex.h>    /* Standart Library of Complex Numbers */

int main()
{
    double complex z1 = 1.0 + 3.0 * I;
    double complex z2 = 1.0 - 4.0 * I;

    printf("Working with complex numbers:\n");
    printf("Starting values: Z1 = %.2f  + %.2fi\tZ2 = %.2f  + %.2fi\n",creal(z1),cimag(z1),creal(z2),cimag(z2));
    double complex sum = z1 + z2;
    printf("The sum: Z1 + Z2 = %.2f %+.2fi\n", creal(sum), cimag(sum));
    return 0;
}

As you can see, again the faulty libstdc++-6.dll comes into play. Can anyone suggest me any workaround this time, hopefully without downgrading to previous versions of MinGW, as I would then have to rebuild all my libraries.

Any help will be appreciated!

Community
  • 1
  • 1
  • Wellcome to SO. This is probably not the right site for your issue. With something like that you should file a bug report to your platform provider. And, BTW, C99 and C++ are generally not compatible, in particular complex numbers seem to be managed differently between the two. – Jens Gustedt Apr 04 '13 at 11:55
  • @JensGustedt: this underlying problem is not platform dependent, and this question is good for SO. – rubenvb Apr 04 '13 at 12:52
  • @devnull please don't spew irrelevant recommendations. – rubenvb Apr 04 '13 at 12:52
  • @rubenvb So a `relevant` recommendation would be to write up a bug report for MinGW? But even that would require some information -- like the compiler (and version). – devnull Apr 04 '13 at 13:01
  • @rubenvb: Thanks. I knew this was not a problem for just windows because it gave me a segmentation fault! – Binayaka Chakraborty Apr 04 '13 at 14:28
  • @devnull: I personally don't prefer Cygwin. I like to build my own binaries from the sources, and thus am partial to GNUWin32 :) I also posted this question because I found many unanswered questions that have their problem root in that particular dll. – Binayaka Chakraborty Apr 04 '13 at 14:32
  • @JensGustedt: Glad to be here :D Thanks for the warm welcome. I know the issue regarding complex numbers in C99 and C++, but I didn't believe that would translate to such a large difference in their type of execution. – Binayaka Chakraborty Apr 04 '13 at 14:35

1 Answers1

1

Like Jens said I don't think the complex.h header file is compatible with C++. In C++ you should be using the complex header like so:

#include <iostream>
#include <complex>

int main()
{
  std::complex<double> c1(1.0,1.0), c2 ;

  c2 = pow(c1,2.0);

  std::cout << c1 << "  " << c2 << std::endl; 
}
Shafik Yaghmour
  • 154,301
  • 39
  • 440
  • 740