Hi,

Running Win2k, AS perl build 626 (5.6.1) and msvc++ 6.0.

When I try to run the script below, I get the following error message:

Use of inherited AUTOLOAD for non-method main::mult_gcd() is deprecated at
gcd_mult.pl line 55.
Can't locate auto/main/mult_gcd.al in @INC (@INC contains: D:/pscrpt/inline
/_Inline/lib D:/Perl/lib D:/Perl/site/lib .) at gcd_mult.pl line 55

Can someone enlighten me on the problem and possible solution ? They're
fairly simple functions, and any explanation might help me in my
understanding of both C and this module.

The second of the 2 functions (which is called by the first) works quite
well in an inline script that finds the
gcd of just 2 numbers (and it's written into that script exactly as appears
here).

#!perl -w

use Inline C => <<END_OF_C_CODE;

#include <iostream.h>

    /* returns the gcd of x1, x2...xm */
    int mult_gcd (int m, int *x)
    {
         size_t i;
         int g;

         if (m < 1)
            return 0;
         g = x[0];
         for (i=1; i<m; ++i) {
            g = gcd(g, x[i]);
/* optimization, since for random x[i],
g==1 60% of the time: */
             if (g == 1)
                  return 1;
         }
         return g;
    }


/* the code below works fine inline in a script
   that obtains the gcd of just 2 numbers  */

    /* returns gcd of x and y */
    int gcd (int x, int y)
    {
         int g;
         if (x < 0)
       x = -x;
         if (y < 0)
       y = -y;
         if (x + y == 0)
       ERROR;
         g = y;
         while (x > 0) {
       g = x;
       x = y % x;
       y = g;
         }
         return g;
    }

END_OF_C_CODE

@numbers = (54, 108, 216, 42);

$count = scalar(@numbers);

$gcd = mult_gcd($count, @numbers); # Line 55

print "Greatest common denominator = ", $gcd, "\n";

############


This code has been copied, btw, and I'm not too sure what to do about the
reference to 'ERROR' in the second function. I've tried deleting that 'if'
statement entirely and it makes no difference. When I run this code in C, I
change 'ERROR' to 'printf( "ERROR\n" )' and then the whole lot works fine -
but 'Inline' seems to not like that change, complaining of '
newline in constant' and 'syntax error : missing ')' ' in the .xs file.

Any help appreciated.

Cheers,
Rob




Reply via email to