Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   migrating c code to perl (http://www.velocityreviews.com/forums/t884590-migrating-c-code-to-perl.html)

chetan 01-13-2004 03:19 AM

migrating c code to perl
 
Is there any way (tool) to migrate/convert c code to perl ?


Martien Verbruggen 01-13-2004 04:17 AM

Re: migrating c code to perl
 
On Tue, 13 Jan 2004 08:49:54 +0530,
chetan <chetan@netapp.com> wrote:
> Is there any way (tool) to migrate/convert c code to perl ?


None that I know of. If there was such a tool, I probably wouldn't use
it, and I certainly wouldn't trust it.

There are many things that work in C, are very idiomatic, but which
are just not the right way to approach things in Perl. There are
things that are possible in C, and simply not possible at all in Perl.

For example, walking a string in C by incrementing a pointer until you
reach a null byte, is normal in C. In Perl, that is not what you do.

Another example is the use of machine-specific register tricks, or
machine-specific address tricks. In (machine-specific variants of) C
you can set a pointer to a fixed address, which is meaningful to the
machine, and then manipulate or read that address. You can't do that
in Perl.

Trying to translate C into Perl on a code line by line basis will
always end up with bad code, and most often with something ugly,
unmaintainable, if it is possible at all.


If you can't rewite the logic in Perl, maybe you should try to make
your C code available as a library, and provide some access points to
this library to Perl, with XS, SWIG, Inline::C or soemthing like that.

The question is: Why do you want to rewrite it? The best option
depends on the answer you give to that question.

Martien
--
|
Martien Verbruggen |
Trading Post Australia | What's another word for Thesaurus?
|

chetan 01-13-2004 04:48 AM

Re: migrating c code to perl
 
i have a tool written in c. Need to have the same functianlities in perl
so that they could be a part of an existing framework which is already
there in perl. I am going through "perlxs and friends" (i am fresh to
the world of perl). was thinking if there are similar utilities which
could help me atain my goal.
I agree with you that most of the aspects couldnt be taken care of
when we want to convert c to perl and you are right, line by line
conversion doesnt make any sense..i agree with you in this...
will check out SWIG Inline and similar stuff.
Thanks for the suggestions :)


Martien Verbruggen wrote:
> On Tue, 13 Jan 2004 08:49:54 +0530,
> chetan <chetan@netapp.com> wrote:
>
>>Is there any way (tool) to migrate/convert c code to perl ?

>
>
> None that I know of. If there was such a tool, I probably wouldn't use
> it, and I certainly wouldn't trust it.
>
> There are many things that work in C, are very idiomatic, but which
> are just not the right way to approach things in Perl. There are
> things that are possible in C, and simply not possible at all in Perl.
>
> For example, walking a string in C by incrementing a pointer until you
> reach a null byte, is normal in C. In Perl, that is not what you do.
>
> Another example is the use of machine-specific register tricks, or
> machine-specific address tricks. In (machine-specific variants of) C
> you can set a pointer to a fixed address, which is meaningful to the
> machine, and then manipulate or read that address. You can't do that
> in Perl.
>
> Trying to translate C into Perl on a code line by line basis will
> always end up with bad code, and most often with something ugly,
> unmaintainable, if it is possible at all.
>
>
> If you can't rewite the logic in Perl, maybe you should try to make
> your C code available as a library, and provide some access points to
> this library to Perl, with XS, SWIG, Inline::C or soemthing like that.
>
> The question is: Why do you want to rewrite it? The best option
> depends on the answer you give to that question.
>
> Martien



Tassilo v. Parseval 01-13-2004 06:35 AM

Re: migrating c code to perl
 
Also sprach chetan:

> Is there any way (tool) to migrate/convert c code to perl ?


No, but you can make an XS module that uses the C code base. I did that
once for File::Locate which was the only Perl module so far that merely
took me one afternoon to complete. I simply copied the relevant code
from the GNU findutils and added the necessary stuff from the perlapi.

Perl and C work together exceptionally well, therefore integrating C
into Perl is often a better solution than rewriting (it wont result in a
penalty-hit eithe).

Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus}) !JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexi ixesixeseg;y~\n~~dddd;eval


All times are GMT. The time now is 03:57 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.