CHAPTER 10
Writing C Modules 
with Inline::C
I
NLINE
::C
1 PROVIDES
 a new way to write Perl modules with C. Instead of separating 
out the Perl and C parts of your module into different files, you can include them 
both in the same file. Instead of learning a new programming language (XS), you 
can create C functions in pure C. If this sounds pretty great, it is! My prediction is 
that the majority of new C modules will be written using Inline::C. It's easy, it 
works, and what more could you ask for?
Inline::C is essentially a compiler for XS. You give Inline::C some C code. Inline::C 
takes that code, parses it, and produces an XS wrapper to make that code callable 
from Perl. This XS code is written out to disk in a special temporary directory. Then 
Inline::C compiles the code using the normal XS tools: ExtUtils::MakeMaker, 
xsubpp, and your system's C compiler This compiled code is saved to disk and then 
loaded into memory.
Since the compiled code is saved to disk, it can be reused as long as the C code 
hasn't changed. This magic is accomplished by using Digest::MD5 to produce a 
fingerprint of your code. When that fingerprint is changed, the code is automatically 
recompiled the next time it's passed to Inline::C.
Inline::C Walkthrough
Here's a simple example script that uses Inline::C to print out  Just Another Perl 
Hacker :
#!/usr/bin/perl  w
use Inline C => <
  void japh() {
    PerlIO_stdoutf("Just Another Perl Hacker.\n");
  }
END_OF_C
japh();
1. Written by Brian Ingerson and available on a CPAN mirror near you
237






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

web hosting perl

 

Our partners: PHP: Hypertext Preprocessor Best Web Hosting Java Web Hosting Inexpensive Web Hosting  Jsp Web Hosting

Cheapest Web Hosting Jsp Hosting Cheap Hosting

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved