Hi all,

> 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.


For completeness, I did write up the recipe and submitted it as an issue on 
github about 3 days ago,

https://github.com/ingydotnet/inline-c-pm/issues/56 
<https://github.com/ingydotnet/inline-c-pm/issues/56>

There havn't been any comments made so far, so I'm not sure if its being 
considered for the C Cookbook.
Also, it looks like no updates were made to Inline::C for the last two years.

Cheers,
Ron.

> On 8 Dec 2016, at 3:08 pm, sisyph...@optusnet.com.au wrote:
> 
> 
> From: Ron Grunwald via inline
> Sent: Thursday, December 08, 2016 1:44 AM
> To: inline@perl.org
> Subject: Inline::C Cookbook addition
> Hello all,
> 
>> The code example:
>> 
>> use strict;
>> use warnings;
>> use Inline C => Config => ccflagsex => "-std=c99";
>> use Inline C => "DATA";
>> 
>> our $mesh_data = "MESH-POINTS 0.0 0.0 0.5 0.25 1.0 0.5 1.5 0.75";
>> CalcSurfaceHeights();
>> 
>> __DATA__
>> __C__
>> #define N_MP 4
>> 
>> void CalcSurfaceHeights() {
>>   double x[N_MP], y[N_MP], z;
>>   char   *mesh_data = SvPV_nolen(get_sv("main::mesh_data", 0));
>> 
>>   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);
>> 
>>   for (int ix=0; ix < N_MP; ix++) {
>>      z = 0.5*( sin(x[ix]) + sin(y[ix]) );
>> 
>>      printf("Surface-Height: %6.3f Mesh-Point: %6.2f, %6.2f\n",
>>          z, x[ix], y[ix]);
>>   }
>> }
> 
> The "use Inline C => Config => ..." line can be removed if you rewrite the 
> __C__ section as:
> 
> __DATA__
> __C__
> #define N_MP 4
> 
> void CalcSurfaceHeights() {
>  double x[N_MP], y[N_MP], z;
>  int ix;
>  char   *mesh_data = SvPV_nolen(get_sv("main::mesh_data", 0));
> 
>  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);
> 
>  for (ix=0; ix < N_MP; ix++) {
>     z = 0.5*( sin(x[ix]) + sin(y[ix]) );
> 
>     printf("Surface-Height: %6.3f Mesh-Point: %6.2f, %6.2f\n",
>            z, x[ix], y[ix]);
>  }
> }
> 
> 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.
> 
> 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.
> 
> Cheers,
> Rob
> 

Reply via email to