Discussion:
A possible error in lcc-win wrt static init of complex...
(too old to reply)
Chris M. Thomasson
2017-05-06 18:52:52 UTC
Permalink
Raw Message
I boiled down the error I get in lcc-win to the following simple program
that works for me on my GCC without any warnings whatsoever:
________________________
#include <stdio.h>
#include <complex.h>


struct foo
{
double complex z;
};


int main(void)
{
struct foo f = { -0.75 + 0.06 * I };
printf("z = %1f%+1fi\n", creal(f.z), cimag(f.z));
return 0;
}
________________________


If I run this code on lcc-win64, I get an actual compiler error:
________________________
Wedit output window build: Sat May 06 11:44:26 2017
Error c:\testing_123\testing_123.c 13 Compiler error (trap). Stopping
compilation
Compilation + link time:0.2 sec, Return code: 1
________________________


However, if I change the initialization of f to:
________________________
struct foo f = { { -0.75 + 0.06 * I } };
________________________


lcc-win works fine. The problem is that this now does not work in GCC
for I get the following warning:

braces around scalar initializer

Afaict, we should not need the extra braces?


Any thoughts? Whats going on here? I think GCC is correct. Thanks.
Ben Bacarisse
2017-05-06 19:26:00 UTC
Permalink
Raw Message
Post by Chris M. Thomasson
I boiled down the error I get in lcc-win to the following simple
#include <stdio.h>
#include <complex.h>
struct foo
{
double complex z;
};
int main(void)
{
struct foo f = { -0.75 + 0.06 * I };
printf("z = %1f%+1fi\n", creal(f.z), cimag(f.z));
return 0;
}
<snip>
Post by Chris M. Thomasson
________________________
struct foo f = { { -0.75 + 0.06 * I } };
________________________
lcc-win works fine. The problem is that this now does not work in GCC
braces around scalar initializer
Afaict, we should not need the extra braces?
No, you don't need them.
--
Ben.
Chris M. Thomasson
2017-05-06 21:33:47 UTC
Permalink
Raw Message
Post by Ben Bacarisse
Post by Chris M. Thomasson
I boiled down the error I get in lcc-win to the following simple
#include <stdio.h>
#include <complex.h>
struct foo
{
double complex z;
};
int main(void)
{
struct foo f = { -0.75 + 0.06 * I };
printf("z = %1f%+1fi\n", creal(f.z), cimag(f.z));
return 0;
}
<snip>
Post by Chris M. Thomasson
________________________
struct foo f = { { -0.75 + 0.06 * I } };
________________________
lcc-win works fine. The problem is that this now does not work in GCC
braces around scalar initializer
Afaict, we should not need the extra braces?
No, you don't need them.
Agreed. This has to be a bug in lcc-win.
Chris M. Thomasson
2017-05-06 21:30:27 UTC
Permalink
Raw Message
Post by Chris M. Thomasson
I boiled down the error I get in lcc-win to the following simple program
________________________
#include <stdio.h>
#include <complex.h>
struct foo
{
double complex z;
};
int main(void)
{
struct foo f = { -0.75 + 0.06 * I };
printf("z = %1f%+1fi\n", creal(f.z), cimag(f.z));
^^^^^^^^^^^^^^^^^^

I meant:

printf("z = %lf%+lfi\n", creal(f.z), cimag(f.z));

Lowercase l not 1. It makes no difference wrt the error in lcc-win or
the working GCC. Also, fwiw, when I add the extra braces in lcc-win, it
compiles but gives totally wrong output:

z = 0.000000+0.000000i

NO! GCC gives:

z = -0.750000+0.060000i

ahhh, that's better.
Noob
2017-05-08 08:51:44 UTC
Permalink
Raw Message
Post by Chris M. Thomasson
I boiled down the error I get in lcc-win to the following simple program
IMO, such bug reports should be either sent directly to Jacob,
and/or posted to comp.compilers.lcc

I don't see what they bring to comp.lang.c

Just because the author of lcc-win is a regular here, doesn't
make this NG a proper support channel.

Regards.
David Brown
2017-05-08 10:21:19 UTC
Permalink
Raw Message
Post by Noob
Post by Chris M. Thomasson
I boiled down the error I get in lcc-win to the following simple program
IMO, such bug reports should be either sent directly to Jacob,
and/or posted to comp.compilers.lcc
I don't see what they bring to comp.lang.c
Just because the author of lcc-win is a regular here, doesn't
make this NG a proper support channel.
I think the post was to find out what behaviour is correct in C, since
it was different for lcc-win and gcc. That is a perfectly legitimate
thing to ask here.

Having confirmation that his code is correct, and lcc-win is therefore
wrong, the actual bug report should go to Jacob, his website, the lcc
newsgroup, or somewhere like that.
Keith Thompson
2017-05-08 16:17:14 UTC
Permalink
Raw Message
Post by Noob
Post by Chris M. Thomasson
I boiled down the error I get in lcc-win to the following simple program
IMO, such bug reports should be either sent directly to Jacob,
and/or posted to comp.compilers.lcc
I don't see what they bring to comp.lang.c
Just because the author of lcc-win is a regular here, doesn't
make this NG a proper support channel.
Agreed.

The original error was an internal compiler error in lcc-win.
Such an error *always* indicates a compiler bug.
--
Keith Thompson (The_Other_Keith) kst-***@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
jacobnavia
2017-05-08 17:23:58 UTC
Permalink
Raw Message
Post by Chris M. Thomasson
I boiled down the error I get in lcc-win to the following simple program
________________________
#include <stdio.h>
#include <complex.h>
struct foo
{
double complex z;
};
int main(void)
{
struct foo f = { -0.75 + 0.06 * I };
printf("z = %1f%+1fi\n", creal(f.z), cimag(f.z));
return 0;
}
________________________
________________________
Wedit output window build: Sat May 06 11:44:26 2017
Error c:\testing_123\testing_123.c 13 Compiler error (trap). Stopping
compilation
Compilation + link time:0.2 sec, Return code: 1
________________________
________________________
struct foo f = { { -0.75 + 0.06 * I } };
________________________
lcc-win works fine. The problem is that this now does not work in GCC
braces around scalar initializer
Afaict, we should not need the extra braces?
Any thoughts? Whats going on here? I think GCC is correct. Thanks.
Yes, this is a bug. The problem is the special syntax needed for parsing
an addition that should yield a structure of two fields.

I think

struct foo = {0.75,0.06};

could work better but that wouldn't be a solution, I have to fix this.

Thanks for this bug report
Chris M. Thomasson
2017-05-11 20:47:47 UTC
Permalink
Raw Message
Post by jacobnavia
Post by Chris M. Thomasson
I boiled down the error I get in lcc-win to the following simple program
________________________
#include <stdio.h>
#include <complex.h>
struct foo
{
double complex z;
};
int main(void)
{
struct foo f = { -0.75 + 0.06 * I };
printf("z = %1f%+1fi\n", creal(f.z), cimag(f.z));
return 0;
}
________________________
________________________
Wedit output window build: Sat May 06 11:44:26 2017
Error c:\testing_123\testing_123.c 13 Compiler error (trap). Stopping
compilation
Compilation + link time:0.2 sec, Return code: 1
________________________
________________________
struct foo f = { { -0.75 + 0.06 * I } };
________________________
lcc-win works fine. The problem is that this now does not work in GCC
braces around scalar initializer
Afaict, we should not need the extra braces?
Any thoughts? Whats going on here? I think GCC is correct. Thanks.
Yes, this is a bug. The problem is the special syntax needed for parsing
an addition that should yield a structure of two fields.
I think
struct foo = {0.75,0.06};
could work better but that wouldn't be a solution, I have to fix this.
Thanks for this bug report
No problem Jacob. Thank you for your time wrt fixing the issue.
Seriously, I really do appreciate it. :^)

Loading...