Re: Inline::C Cookbook addition

[email protected] (Ron Grunwald via inline) Sat, 10 Dec 2016 07:02:39 +0800
Newsgroups perl.inline
Message-ID <[email protected]>
--Apple-Mail=_F9BEB307-5E84-41CF-9C32-AE31611E8654
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=iso-8859-1

Hi Rob,

Thank you for testing the example with your compiler, and also thank you =
for the wonderful advice. I will remove the index variable declaration =
from the for loop.

>> for (int ix=3D0; ix < N_MP; ix++) {

Cheers,
Ron.

> On 9 Dec 2016, at 7:24 am, <[email protected]> =
<[email protected]> wrote:
>=20
> Hi Ron,
>=20
> The original rendition compiles on Windows ok if the compiler being =
used is gcc. (I think you said you had tested it on ActivePerl 5.24.0 =
and found it to be fine.)
>=20
> However, with my MS compiler (Microsoft (R) C/C++ Optimizing Compiler =
Version 14.00.40310.41 for AMD64), I got:
>=20
> Microsoft (R) Program Maintenance Utility   Version 7.00.8882
> Copyright (C) Microsoft Corp 1988-2000. All rights reserved.
>=20
>       cl -c  -I"C:/_32/pscrpt/inline"  -nologo -GF -W3 -MD -Zi =
-DNDEBUG -Ox -G
> L -fp:precise -DWIN32 -D_CONSOLE -DNO_STRICT -DWIN64 -DCONSERVATIVE =
-DPERL_TEXTM
> ODE_SCRIPTS -DUSE_SITECUSTOMIZE -DPERL_IMPLICIT_CONTEXT =
-DPERL_IMPLICIT_SYS  -DUS
> E_PERLIO -std=3Dc99 -MD -Zi -DNDEBUG -Ox -GL -fp:precise    =
-DVERSION=3D\"0.00\"  -D
> XS_VERSION=3D\"0.00\"  "-IC:\_64\ap1600\lib\CORE"   try_pl_7dcf.c
> cl : Command line warning D9002 : ignoring unknown option '-std=3Dc99'
>=20
>=20
> Admittedly, that MS compiler is getting a little bit old but my =
understanding is that even the most recent MS compilers are not C99 =
compliant (as MS like to make up their own rules).
> FAIK there might also be other non C99 compliant compilers in use.
>=20
> Both ActiveState and StrawberryPerl provide gcc-based perls for =
Windows, but there are still people using MS compilers with perl on =
Windows. (I'm not really one of those people - I keep that MS compiler =
for reference only.)
>=20
> So I think, for a cookbook especially, it's best to code for the =
lowest common denominator unless that's impractical - though I'm sure =
that use of non C99 compliant compilers with perl is the exception =
rather than the rule.
>=20
> Cheers,
> Rob
>=20
> -----Original Message----- From: Ron Grunwald via inline
> Sent: Friday, December 09, 2016 9:27 AM
> To: [email protected]
> Cc: [email protected]
> Subject: Re: Inline::C Cookbook addition
>=20
> Hi Rob,
>=20
> So I gather that the example in its original state did not compile on =
Windows? I would be somewhat surprised that there are still C compilers =
in use that are not C99 compliant.
>=20
> Many thanks for your suggestions, and I will follow your advice on =
using the github process.
>=20
> Cheers,
> Ron.
>=20
>> On 8 Dec 2016, at 3:08 pm, [email protected] wrote:
>>=20
>> The "use Inline C =3D> Config =3D> ..." line can be removed if you =
rewrite the __C__ section as:
>>=20
>> __DATA__
>> __C__
>> #define N_MP 4
>>=20
>> void CalcSurfaceHeights() {
>> double x[N_MP], y[N_MP], z;
>> int ix;
>> char   *mesh_data =3D SvPV_nolen(get_sv("main::mesh_data", 0));
>>=20
>> sscanf(mesh_data, "MESH-POINTS %lf%lf%lf%lf%lf%lf%lf%lf",
>>                   x, y, x+1, y+1, x+2, y+2, x+3, y+3);
>>=20
>> for (ix=3D0; ix < N_MP; ix++) {
>>    z =3D 0.5*( sin(x[ix]) + sin(y[ix]) );
>>=20
>>    printf("Surface-Height: %6.3f Mesh-Point: %6.2f, %6.2f\n",
>>           z, x[ix], y[ix]);
>> }
>> }
>>=20
>> All I've done is move the declaration of "ix" from the for() loop to =
the declaration section at the beginning of CalcSurfaceHeights().
>> This then enables the code to compile using compilers (such as =
Microsoft compilers) that are not C99-compliant.
>>=20
>> This mailing list is very quiet these days and I think your request =
will probably fall "through the cracks" unless you submit it as a github =
"Issue" or a github pull request.
>>=20
>> Cheers,
>> Rob


--Apple-Mail=_F9BEB307-5E84-41CF-9C32-AE31611E8654
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
	charset=iso-8859-1

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html =
charset=3Diso-8859-1"></head><body style=3D"word-wrap: break-word; =
-webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" =
class=3D"">Hi Rob,<div class=3D""><br class=3D""></div><div =
class=3D"">Thank you for testing the example with your compiler, and =
also thank you for the wonderful advice. I will remove the index =
variable declaration from the for loop.</div><div class=3D""><br =
class=3D""></div><div class=3D""><blockquote type=3D"cite" =
class=3D""><blockquote type=3D"cite" class=3D""><font face=3D"Courier" =
class=3D"">for (int ix=3D0; ix &lt; N_MP; ix++) {<br =
class=3D""></font></blockquote></blockquote>
<div class=3D""><br class=3D""></div>Cheers,</div><div =
class=3D"">Ron.</div><div class=3D""><br class=3D""><div><blockquote =
type=3D"cite" class=3D""><div class=3D"">On 9 Dec 2016, at 7:24 am, =
&lt;<a href=3D"mailto:[email protected]" =
class=3D"">[email protected]</a>&gt; &lt;<a =
href=3D"mailto:[email protected]" =
class=3D"">[email protected]</a>&gt; wrote:</div><br =
class=3D"Apple-interchange-newline"><div class=3D"">Hi Ron,<br =
class=3D""><br class=3D"">The original rendition compiles on Windows ok =
if the compiler being used is gcc. (I think you said you had tested it =
on ActivePerl 5.24.0 and found it to be fine.)<br class=3D""><br =
class=3D"">However, with my MS compiler (Microsoft (R) C/C++ Optimizing =
Compiler Version 14.00.40310.41 for AMD64), I got:<br class=3D""><br =
class=3D"">Microsoft (R) Program Maintenance Utility &nbsp;&nbsp;Version =
7.00.8882<br class=3D"">Copyright (C) Microsoft Corp 1988-2000. All =
rights reserved.<br class=3D""><br class=3D"">&nbsp; &nbsp; &nbsp; cl -c =
&nbsp;-I"C:/_32/pscrpt/inline" &nbsp;-nologo -GF -W3 -MD -Zi -DNDEBUG =
-Ox -G<br class=3D"">L -fp:precise -DWIN32 -D_CONSOLE -DNO_STRICT =
-DWIN64 -DCONSERVATIVE -DPERL_TEXTM<br class=3D"">ODE_SCRIPTS =
-DUSE_SITECUSTOMIZE -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS =
&nbsp;-DUS<br class=3D"">E_PERLIO -std=3Dc99 -MD -Zi -DNDEBUG -Ox -GL =
-fp:precise &nbsp;&nbsp;&nbsp;-DVERSION=3D\"0.00\" &nbsp;-D<br =
class=3D"">XS_VERSION=3D\"0.00\" &nbsp;"-IC:\_64\ap1600\lib\CORE" =
&nbsp;&nbsp;try_pl_7dcf.c<br class=3D"">cl : Command line warning D9002 =
: ignoring unknown option '-std=3Dc99'</div></blockquote><blockquote =
type=3D"cite" class=3D""><div class=3D""><br =
class=3D""></div></blockquote><blockquote type=3D"cite" class=3D""><div =
class=3D""><br class=3D""></div></blockquote><blockquote type=3D"cite" =
class=3D""><div class=3D"">Admittedly, that MS compiler is getting a =
little bit old but my understanding is that even the most recent MS =
compilers are not C99 compliant (as MS like to make up their own =
rules).<br class=3D"">FAIK there might also be other non C99 compliant =
compilers in use.<br class=3D""><br class=3D"">Both ActiveState and =
StrawberryPerl provide gcc-based perls for Windows, but there are still =
people using MS compilers with perl on Windows. (I'm not really one of =
those people - I keep that MS compiler for reference only.)<br =
class=3D""><br class=3D"">So I think, for a cookbook especially, it's =
best to code for the lowest common denominator unless that's impractical =
- though I'm sure that use of non C99 compliant compilers with perl is =
the exception rather than the rule.<br class=3D""><br =
class=3D"">Cheers,<br class=3D"">Rob<br class=3D""><br =
class=3D"">-----Original Message----- From: Ron Grunwald via inline<br =
class=3D"">Sent: Friday, December 09, 2016 9:27 AM<br class=3D"">To: <a =
href=3D"mailto:[email protected]" =
class=3D"">[email protected]</a><br class=3D"">Cc: <a =
href=3D"mailto:[email protected]" class=3D"">[email protected]</a><br =
class=3D"">Subject: Re: Inline::C Cookbook addition<br class=3D""><br =
class=3D"">Hi Rob,<br class=3D""><br class=3D"">So I gather that the =
example in its original state did not compile on Windows? I would be =
somewhat surprised that there are still C compilers in use that are not =
C99 compliant.<br class=3D""><br class=3D"">Many thanks for your =
suggestions, and I will follow your advice on using the github =
process.<br class=3D""><br class=3D"">Cheers,<br class=3D"">Ron.<br =
class=3D""><br class=3D""><blockquote type=3D"cite" class=3D"">On 8 Dec =
2016, at 3:08 pm, <a href=3D"mailto:[email protected]" =
class=3D"">[email protected]</a> wrote:<br class=3D""><br =
class=3D"">The "use Inline C =3D&gt; Config =3D&gt; ..." line can be =
removed if you rewrite the __C__ section as:<br class=3D""><br =
class=3D"">__DATA__<br class=3D"">__C__<br class=3D"">#define N_MP 4<br =
class=3D""><br class=3D"">void CalcSurfaceHeights() {<br class=3D""> =
double x[N_MP], y[N_MP], z;<br class=3D""> int ix;<br class=3D""> char =
&nbsp;&nbsp;*mesh_data =3D SvPV_nolen(get_sv("main::mesh_data", 0));<br =
class=3D""><br class=3D""> sscanf(mesh_data, "MESH-POINTS =
%lf%lf%lf%lf%lf%lf%lf%lf",<br class=3D""> =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x, y, x+1, y+1, x+2, y+2, x+3, =
y+3);<br class=3D""><br class=3D""> for (ix=3D0; ix &lt; N_MP; ix++) =
{<br class=3D""> &nbsp;&nbsp;&nbsp;z =3D 0.5*( sin(x[ix]) + sin(y[ix]) =
);<br class=3D""><br class=3D""> =
&nbsp;&nbsp;&nbsp;printf("Surface-Height: %6.3f Mesh-Point: %6.2f, =
%6.2f\n",<br class=3D""> =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;z, x[ix], =
y[ix]);<br class=3D""> }<br class=3D"">}<br class=3D""><br class=3D"">All =
I've done is move the declaration of "ix" from the for() loop to the =
declaration section at the beginning of CalcSurfaceHeights().<br =
class=3D"">This then enables the code to compile using compilers (such =
as Microsoft compilers) that are not C99-compliant.<br class=3D""><br =
class=3D"">This mailing list is very quiet these days and I think your =
request will probably fall "through the cracks" unless you submit it as =
a github "Issue" or a github pull request.<br class=3D""><br =
class=3D"">Cheers,<br class=3D"">Rob<br =
class=3D""></blockquote></div></blockquote></div><br =
class=3D""></div></body></html>=

--Apple-Mail=_F9BEB307-5E84-41CF-9C32-AE31611E8654--