Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / man / man3 / Inline::C.3
CommitLineData
86530b38
AT
1.\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13
2.\"
3.\" Standard preamble:
4.\" ========================================================================
5.de Sh \" Subsection heading
6.br
7.if t .Sp
8.ne 5
9.PP
10\fB\\$1\fR
11.PP
12..
13.de Sp \" Vertical space (when we can't use .PP)
14.if t .sp .5v
15.if n .sp
16..
17.de Vb \" Begin verbatim text
18.ft CW
19.nf
20.ne \\$1
21..
22.de Ve \" End verbatim text
23.ft R
24.fi
25..
26.\" Set up some character translations and predefined strings. \*(-- will
27.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
28.\" double quote, and \*(R" will give a right double quote. | will give a
29.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
30.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
31.\" expand to `' in nroff, nothing in troff, for use with C<>.
32.tr \(*W-|\(bv\*(Tr
33.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
34.ie n \{\
35. ds -- \(*W-
36. ds PI pi
37. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
38. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
39. ds L" ""
40. ds R" ""
41. ds C` ""
42. ds C' ""
43'br\}
44.el\{\
45. ds -- \|\(em\|
46. ds PI \(*p
47. ds L" ``
48. ds R" ''
49'br\}
50.\"
51.\" If the F register is turned on, we'll generate index entries on stderr for
52.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
53.\" entries marked with X<> in POD. Of course, you'll have to process the
54.\" output yourself in some meaningful fashion.
55.if \nF \{\
56. de IX
57. tm Index:\\$1\t\\n%\t"\\$2"
58..
59. nr % 0
60. rr F
61.\}
62.\"
63.\" For nroff, turn off justification. Always turn off hyphenation; it makes
64.\" way too many mistakes in technical documents.
65.hy 0
66.if n .na
67.\"
68.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69.\" Fear. Run. Save yourself. No user-serviceable parts.
70. \" fudge factors for nroff and troff
71.if n \{\
72. ds #H 0
73. ds #V .8m
74. ds #F .3m
75. ds #[ \f1
76. ds #] \fP
77.\}
78.if t \{\
79. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80. ds #V .6m
81. ds #F 0
82. ds #[ \&
83. ds #] \&
84.\}
85. \" simple accents for nroff and troff
86.if n \{\
87. ds ' \&
88. ds ` \&
89. ds ^ \&
90. ds , \&
91. ds ~ ~
92. ds /
93.\}
94.if t \{\
95. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
101.\}
102. \" troff and (daisy-wheel) nroff accents
103.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110.ds ae a\h'-(\w'a'u*4/10)'e
111.ds Ae A\h'-(\w'A'u*4/10)'E
112. \" corrections for vroff
113.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115. \" for low resolution devices (crt and lpr)
116.if \n(.H>23 .if \n(.V>19 \
117\{\
118. ds : e
119. ds 8 ss
120. ds o a
121. ds d- d\h'-1'\(ga
122. ds D- D\h'-1'\(hy
123. ds th \o'bp'
124. ds Th \o'LP'
125. ds ae ae
126. ds Ae AE
127.\}
128.rm #[ #] #H #V #F C
129.\" ========================================================================
130.\"
131.IX Title "C 3"
132.TH C 3 "2002-11-04" "perl v5.8.0" "User Contributed Perl Documentation"
133.SH "NAME"
134Inline::C \- Write Perl Subroutines in C
135.SH "DESCRIPTION"
136.IX Header "DESCRIPTION"
137\&\f(CW\*(C`Inline::C\*(C'\fR is a module that allows you to write Perl subroutines in C.
138Since version 0.30 the Inline module supports multiple programming
139languages and each language has its own support module. This document
140describes how to use Inline with the C programming language. It also
141goes a bit into Perl C internals.
142.PP
143If you want to start working with programming examples right away, check
144out Inline::C\-Cookbook. For more information on Inline in general,
145see Inline.
146.SH "Usage"
147.IX Header "Usage"
148You never actually use \f(CW\*(C`Inline::C\*(C'\fR directly. It is just a support
149module for using \f(CW\*(C`Inline.pm\*(C'\fR with C. So the usage is always:
150.PP
151.Vb 1
152\& use Inline C => ...;
153.Ve
154.PP
155or
156.PP
157.Vb 1
158\& bind Inline C => ...;
159.Ve
160.SH "Function Definitions"
161.IX Header "Function Definitions"
162The Inline grammar for C recognizes certain function definitions (or
163signatures) in your C code. If a signature is recognized by Inline, then
164it will be available in Perl\-space. That is, Inline will generate the
165\&\*(L"glue\*(R" necessary to call that function as if it were a Perl subroutine.
166If the signature is not recognized, Inline will simply ignore it, with
167no complaints. It will not be available from Perl\-space, although it
168\&\fIwill\fR be available from C\-space.
169.PP
170Inline looks for ANSI/prototype style function definitions. They must be
171of the form:
172.PP
173.Vb 1
174\& return-type function-name ( type-name-pairs ) { ... }
175.Ve
176.PP
177The most common types are: \f(CW\*(C`int\*(C'\fR, \f(CW\*(C`long\*(C'\fR, \f(CW\*(C`double\*(C'\fR, \f(CW\*(C`char*\*(C'\fR, and
178\&\f(CW\*(C`SV*\*(C'\fR. But you can use any type for which Inline can find a typemap.
179Inline uses the \f(CW\*(C`typemap\*(C'\fR file distributed with Perl as the default.
180You can specify more typemaps with the \s-1TYPEMAPS\s0 configuration option.
181.PP
182A return type of \f(CW\*(C`void\*(C'\fR may also be used. The following are examples of
183valid function definitions.
184.PP
185.Vb 5
186\& int Foo(double num, char* str) {
187\& void Foo(double num, char* str) {
188\& SV* Foo() {
189\& void Foo(SV*, ...) {
190\& long Foo(int i, int j, ...) {
191.Ve
192.PP
193The following definitions would not be recognized:
194.PP
195.Vb 4
196\& Foo(int i) { # no return type
197\& int Foo(float f) { # no (default) typemap for float
198\& int Foo(num, str) double num; char* str; {
199\& void Foo(void) { # void only valid for return type
200.Ve
201.PP
202Notice that Inline only looks for function \fIdefinitions\fR, not function
203\&\fIprototypes\fR. Definitions are the syntax directly preceeding a function
204body. Also Inline does not scan external files, like headers. Only the
205code passed to Inline is used to create bindings; although other
206libraries can linked in, and called from C\-space.
207.SH "C Configuration Options"
208.IX Header "C Configuration Options"
209For information on how to specify Inline configuration options, see
210Inline. This section describes each of the configuration options
211available for C. Most of the options correspond either to MakeMaker or
212\&\s-1XS\s0 options of the same name. See ExtUtils::MakeMaker and perlxs.
213.Sh "\s-1AUTO_INCLUDE\s0"
214.IX Subsection "AUTO_INCLUDE"
215Specifies extra statements to automatically included. They will be added
216onto the defaults. A newline char will be automatically added.
217.PP
218.Vb 1
219\& use Inline C => Config => AUTO_INCLUDE => '#include "yourheader.h"';
220.Ve
221.Sh "\s-1AUTOWRAP\s0"
222.IX Subsection "AUTOWRAP"
223If you '\s-1ENABLE\s0 => \s-1AUTOWRAP\s0', Inline::C will parse function declarations
224(prototype statements) in your C code. For each declaration it can bind
225to, it will create a dummy wrapper that will call the real function
226which may be in an external library. This is a nice convenience for
227functions that would otherwise just require an empty wrapper function.
228.PP
229This is similar to the base functionality you get from \f(CW\*(C`h2xs\*(C'\fR. It can
230be very useful for binding to external libraries.
231.Sh "\s-1BOOT\s0"
232.IX Subsection "BOOT"
233Specifies C code to be executed in the \s-1XS\s0 \s-1BOOT\s0 section. Corresponds to
234the \s-1XS\s0 parameter.
235.Sh "\s-1CC\s0"
236.IX Subsection "CC"
237Specify which compiler to use.
238.Sh "\s-1CCFLAGS\s0"
239.IX Subsection "CCFLAGS"
240Specify extra compiler flags.
241.Sh "\s-1FILTERS\s0"
242.IX Subsection "FILTERS"
243Allows you to specify a list of source code filters. If more than one is
244requested, be sure to group them with an array ref. The filters can
245either be subroutine references or names of filters provided by the
246supplementary Inline::Filters module.
247.PP
248Your source code will be filtered just before it is parsed by Inline.
249The \s-1MD5\s0 fingerprint is generated before filtering. Source code
250filters can be used to do things like stripping out \s-1POD\s0
251documentation, pre-expanding #include statements or whatever else you
252please. For example:
253.PP
254.Vb 2
255\& use Inline C => DATA =>
256\& FILTERS => [Strip_POD => \e&MyFilter => Preprocess ];
257.Ve
258.PP
259Filters are invoked in the order specified. See Inline::Filters for
260more information.
261.Sh "\s-1INC\s0"
262.IX Subsection "INC"
263Specifies an include path to use. Corresponds to the MakeMaker parameter.
264.PP
265.Vb 1
266\& use Inline C => Config => INC => '-I/inc/path';
267.Ve
268.Sh "\s-1LD\s0"
269.IX Subsection "LD"
270Specify which linker to use.
271.Sh "\s-1LDDLFLAGS\s0"
272.IX Subsection "LDDLFLAGS"
273Specify which linker flags to use.
274.PP
275\&\s-1NOTE:\s0
276These flags will completely override the existing flags, instead of
277just adding to them. So if you need to use those too, you must
278respecify them here.
279.Sh "\s-1LIBS\s0"
280.IX Subsection "LIBS"
281Specifies external libraries that should be linked into your code.
282Corresponds to the MakeMaker parameter.
283.PP
284.Vb 1
285\& use Inline C => Config => LIBS => '-lyourlib';
286.Ve
287.PP
288or
289.PP
290.Vb 1
291\& use Inline C => Config => LIBS => '-L/your/path -lyourlib';
292.Ve
293.Sh "\s-1MAKE\s0"
294.IX Subsection "MAKE"
295Specify the name of the 'make' utility to use.
296.Sh "\s-1MYEXTLIB\s0"
297.IX Subsection "MYEXTLIB"
298Specifies a user compiled object that should be linked in. Corresponds
299to the MakeMaker parameter.
300.PP
301.Vb 1
302\& use Inline C => Config => MYEXTLIB => '/your/path/yourmodule.so';
303.Ve
304.Sh "\s-1OPTIMIZE\s0"
305.IX Subsection "OPTIMIZE"
306This controls the MakeMaker \s-1OPTIMIZE\s0 setting. By setting this value to
307\&\f(CW'\-g'\fR, you can turn on debugging support for your Inline extensions.
308This will allow you to be able to set breakpoints in your C code using a
309debugger like gdb.
310.Sh "\s-1PREFIX\s0"
311.IX Subsection "PREFIX"
312Specifies a prefix that will be automatically stripped from C functions
313when they are bound to Perl. Useful for creating wrappers for shared
314library API\-s, and binding to the original names in Perl. Also useful
315when names conflict with Perl internals. Corresponds to the \s-1XS\s0
316parameter.
317.PP
318.Vb 1
319\& use Inline C => Config => PREFIX => 'ZLIB_';
320.Ve
321.Sh "\s-1TYPEMAPS\s0"
322.IX Subsection "TYPEMAPS"
323Specifies extra typemap files to use. These types will modify the
324behaviour of the C parsing. Corresponds to the MakeMaker parameter.
325.PP
326.Vb 1
327\& use Inline C => Config => TYPEMAPS => '/your/path/typemap';
328.Ve
329.SH "C\-Perl Bindings"
330.IX Header "C-Perl Bindings"
331This section describes how the \f(CW\*(C`Perl\*(C'\fR variables get mapped to \f(CW\*(C`C\*(C'\fR
332variables and back again.
333.PP
334First, you need to know how \f(CW\*(C`Perl\*(C'\fR passes arguments back and forth to
335subroutines. Basically it uses a stack (also known as the \fBStack\fR).
336When a sub is called, all of the parenthesized arguments get expanded
337into a list of scalars and pushed onto the \fBStack\fR. The subroutine then
338pops all of its parameters off of the \fBStack\fR. When the sub is done, it
339pushes all of its return values back onto the \fBStack\fR.
340.PP
341The \fBStack\fR is an array of scalars known internally as \f(CW\*(C`SV\*(C'\fR's. The
342\&\fBStack\fR is actually an array of \fBpointers to \s-1SV\s0\fR or \f(CW\*(C`SV*\*(C'\fR; therefore
343every element of the \fBStack\fR is natively a \f(CW\*(C`SV*\*(C'\fR. For \fI\s-1FMTYEWTK\s0\fR
344about this, read \f(CW\*(C`perldoc perlguts\*(C'\fR.
345.PP
346So back to variable mapping. \s-1XS\s0 uses a thing known as \*(L"typemaps\*(R" to turn
347each \f(CW\*(C`SV*\*(C'\fR into a \f(CW\*(C`C\*(C'\fR type and back again. This is done through
348various \s-1XS\s0 macro calls, casts and the Perl \s-1API\s0. See \f(CW\*(C`perldoc perlapi\*(C'\fR.
349\&\s-1XS\s0 allows you to define your own typemaps as well for fancier
350non-standard types such as \f(CW\*(C`typedef\*(C'\fR\-ed structs.
351.PP
352Inline uses the default Perl typemap file for its default types. This
353file is called \f(CW\*(C`/usr/local/lib/perl5/5.6.1/ExtUtils/typemap\*(C'\fR, or
354something similar, depending on your Perl installation. It has
355definitions for over 40 types, which are automatically used by Inline.
356(You should probably browse this file at least once, just to get an idea
357of the possibilities.)
358.PP
359Inline parses your code for these types and generates the \s-1XS\s0 code to map
360them. The most commonly used types are:
361.PP
362.Vb 6
363\& - int
364\& - long
365\& - double
366\& - char*
367\& - void
368\& - SV*
369.Ve
370.PP
371If you need to deal with a type that is not in the defaults, just
372use the generic \f(CW\*(C`SV*\*(C'\fR type in the function definition. Then inside
373your code, do the mapping yourself. Alternatively, you can create
374your own typemap files and specify them using the \f(CW\*(C`TYPEMAPS\*(C'\fR
375configuration option.
376.PP
377A return type of \f(CW\*(C`void\*(C'\fR has a special meaning to Inline. It means that
378you plan to push the values back onto the \fBStack\fR yourself. This is
379what you need to do to return a list of values. If you really don't want
380to return anything (the traditional meaning of \f(CW\*(C`void\*(C'\fR) then simply
381don't push anything back.
382.PP
383If ellipsis or \f(CW\*(C`...\*(C'\fR is used at the end of an argument list, it means
384that any number of \f(CW\*(C`SV*\*(C'\fRs may follow. Again you will need to pop the
385values off of the \f(CW\*(C`Stack\*(C'\fR yourself.
386.PP
387See \*(L"Examples\*(R" below.
388.SH "The Inline Stack Macros"
389.IX Header "The Inline Stack Macros"
390When you write Inline C, the following lines are automatically prepended
391to your code (by default):
392.PP
393.Vb 4
394\& #include "EXTERN.h"
395\& #include "perl.h"
396\& #include "XSUB.h"
397\& #include "INLINE.h"
398.Ve
399.PP
400The file \f(CW\*(C`INLINE.h\*(C'\fR defines a set of macros that are useful for
401handling the Perl Stack from your C functions.
402.IP "Inline_Stack_Vars" 4
403.IX Item "Inline_Stack_Vars"
404You'll need to use this one, if you want to use the others. It sets up a
405few local variables: \f(CW\*(C`sp\*(C'\fR, \f(CW\*(C`items\*(C'\fR, \f(CW\*(C`ax\*(C'\fR and \f(CW\*(C`mark\*(C'\fR, for use by the
406other macros. It's not important to know what they do, but I mention
407them to avoid possible name conflicts.
408.Sp
409\&\s-1NOTE:\s0
410Since this macro declares variables, you'll need to put it with your
411other variable declarations at the top of your function. It must
412come before any executable statements and before any other
413\&\f(CW\*(C`Inline_Stack\*(C'\fR macros.
414.IP "Inline_Stack_Items" 4
415.IX Item "Inline_Stack_Items"
416Returns the number of arguments passed in on the Stack.
417.IP "Inline_Stack_Item(i)" 4
418.IX Item "Inline_Stack_Item(i)"
419Refers to a particular \f(CW\*(C`SV*\*(C'\fR in the Stack, where \f(CW\*(C`i\*(C'\fR is an index
420number starting from zero. Can be used to get or set the value.
421.IP "Inline_Stack_Reset" 4
422.IX Item "Inline_Stack_Reset"
423Use this before pushing anything back onto the Stack. It resets the
424internal Stack pointer to the beginning of the Stack.
425.IP "Inline_Stack_Push(sv)" 4
426.IX Item "Inline_Stack_Push(sv)"
427Push a return value back onto the Stack. The value must be of type \f(CW\*(C`SV*\*(C'\fR.
428.IP "Inline_Stack_Done" 4
429.IX Item "Inline_Stack_Done"
430After you have pushed all of your return values, you must call this macro.
431.IP "Inline_Stack_Return(n)" 4
432.IX Item "Inline_Stack_Return(n)"
433Return \f(CW\*(C`n\*(C'\fR items on the Stack.
434.IP "Inline_Stack_Void" 4
435.IX Item "Inline_Stack_Void"
436A special macro to indicate that you really don't want to return
437anything. Same as:
438.Sp
439.Vb 1
440\& Inline_Stack_Return(0);
441.Ve
442.Sp
443Please note that this macro actually \fBreturns\fR from your function.
444.PP
445Each of these macros is available in 3 different styles to suit your
446coding tastes. The following macros are equivalent.
447.PP
448.Vb 3
449\& Inline_Stack_Vars
450\& inline_stack_vars
451\& INLINE_STACK_VARS
452.Ve
453.PP
454All of this functionality is available through \s-1XS\s0 macro calls as well.
455So why duplicate the functionality? There are a few reasons why I
456decided to offer this set of macros. First, as a convenient way to
457access the Stack. Second, for consistent, self documenting, non-cryptic
458coding. Third, for future compatibility. It occured to me that if a lot
459of people started using \s-1XS\s0 macros for their C code, the interface might
460break under Perl6. By using this set, hopefully I will be able to insure
461future compatibility of argument handling.
462.PP
463Of course, if you use the rest of the Perl \s-1API\s0, your code will most
464likely break under Perl6. So this is not a 100% guarantee. But since
465argument handling is the most common interface you're likely to use, it
466seemed like a wise thing to do.
467.SH "Writing C Subroutines"
468.IX Header "Writing C Subroutines"
469The definitions of your C functions will fall into one of the following
470four categories. For each category there are special considerations.
471.IP "1" 4
472.IX Item "1"
473.Vb 1
474\& int Foo(int arg1, char* arg2, SV* arg3) {
475.Ve
476.Sp
477This is the simplest case. You have a non \f(CW\*(C`void\*(C'\fR return type and a
478fixed length argument list. You don't need to worry about much. All the
479conversions will happen automatically.
480.IP "2" 4
481.IX Item "2"
482.Vb 1
483\& void Foo(int arg1, char* arg2, SV* arg3) {
484.Ve
485.Sp
486In this category you have a \f(CW\*(C`void\*(C'\fR return type. This means that either
487you want to return nothing, or that you want to return a list. In the
488latter case you'll need to push values onto the \fBStack\fR yourself. There
489are a few Inline macros that make this easy. Code something like this:
490.Sp
491.Vb 6
492\& int i, max; SV* my_sv[10];
493\& Inline_Stack_Vars;
494\& Inline_Stack_Reset;
495\& for (i = 0; i < max; i++)
496\& Inline_Stack_Push(my_sv[i]);
497\& Inline_Stack_Done;
498.Ve
499.Sp
500After resetting the Stack pointer, this code pushes a series of return
501values. At the end it uses \f(CW\*(C`Inline_Stack_Done\*(C'\fR to mark the end of the
502return stack.
503.Sp
504If you really want to return nothing, then don't use the
505\&\f(CW\*(C`Inline_Stack_\*(C'\fR macros. If you must use them, then set use
506\&\f(CW\*(C`Inline_Stack_Void\*(C'\fR at the end of your function.
507.IP "3" 4
508.IX Item "3"
509.Vb 1
510\& char* Foo(SV* arg1, ...) {
511.Ve
512.Sp
513In this category you have an unfixed number of arguments. This
514means that you'll have to pop values off the \fBStack\fR yourself. Do
515it like this:
516.Sp
517.Vb 4
518\& int i;
519\& Inline_Stack_Vars;
520\& for (i = 0; i < Inline_Stack_Items; i++)
521\& handle_sv(Inline_Stack_Item(i));
522.Ve
523.Sp
524The return type of \f(CWInline_Stack_Item(i)\fR is \f(CW\*(C`SV*\*(C'\fR.
525.IP "4" 4
526.IX Item "4"
527.Vb 1
528\& void* Foo(SV* arg1, ...) {
529.Ve
530.Sp
531In this category you have both a \f(CW\*(C`void\*(C'\fR return type and an
532unfixed number of arguments. Just combine the techniques from
533Categories 3 and 4.
534.SH "Examples"
535.IX Header "Examples"
536Here are a few examples. Each one is a complete program that you can try
537running yourself. For many more examples see Inline::C\-Cookbook.
538.Sh "Example #1 \- Greetings"
539.IX Subsection "Example #1 - Greetings"
540This example will take one string argument (a name) and print a
541greeting. The function is called with a string and with a number. In the
542second case the number is forced to a string.
543.PP
544Notice that you do not need to \f(CW\*(C`#include <stdio.h\*(C'\fR>. The \f(CW\*(C`perl.h\*(C'\fR
545header file which gets included by default, automatically loads the
546standard C header files for you.
547.PP
548.Vb 8
549\& use Inline C;
550\& greet('Ingy');
551\& greet(42);
552\& __END__
553\& __C__
554\& void greet(char* name) {
555\& printf("Hello %s!\en", name);
556\& }
557.Ve
558.Sh "Example #2 \- and Salutations"
559.IX Subsection "Example #2 - and Salutations"
560This is similar to the last example except that the name is passed in as
561a \f(CW\*(C`SV*\*(C'\fR (pointer to Scalar Value) rather than a string (\f(CW\*(C`char*\*(C'\fR). That
562means we need to convert the \f(CW\*(C`SV\*(C'\fR to a string ourselves. This is
563accomplished using the \f(CW\*(C`SvPVX\*(C'\fR function which is part of the \f(CW\*(C`Perl\*(C'\fR
564internal \s-1API\s0. See \f(CW\*(C`perldoc perlapi\*(C'\fR for more info.
565.PP
566One problem is that \f(CW\*(C`SvPVX\*(C'\fR doesn't automatically convert strings
567to numbers, so we get a little surprise when we try to greet \f(CW42\fR.
568The program segfaults, a common occurence when delving into the
569guts of Perl.
570.PP
571.Vb 8
572\& use Inline C;
573\& greet('Ingy');
574\& greet(42);
575\& __END__
576\& __C__
577\& void greet(SV* sv_name) {
578\& printf("Hello %s!\en", SvPVX(sv_name));
579\& }
580.Ve
581.Sh "Example #3 \- Fixing the problem"
582.IX Subsection "Example #3 - Fixing the problem"
583We can fix the problem in Example #2 by using the \f(CW\*(C`SvPV\*(C'\fR function
584instead. This function will stringify the \f(CW\*(C`SV\*(C'\fR if it does not contain a
585string. \f(CW\*(C`SvPV\*(C'\fR returns the length of the string as it's second
586parameter. Since we don't care about the length, we can just put
587\&\f(CW\*(C`PL_na\*(C'\fR there, which is a special variable designed for that purpose.
588.PP
589.Vb 8
590\& use Inline C;
591\& greet('Ingy');
592\& greet(42);
593\& __END__
594\& __C__
595\& void greet(SV* sv_name) {
596\& printf("Hello %s!\en", SvPV(sv_name, PL_na));
597\& }
598.Ve
599.SH "SEE ALSO"
600.IX Header "SEE ALSO"
601For general information about Inline see Inline.
602.PP
603For sample programs using Inline with C see Inline::C\-Cookbook.
604.PP
605For information on supported languages and platforms see
606Inline-Support.
607.PP
608For information on writing your own Inline Language Support Module, see
609Inline-API.
610.PP
611Inline's mailing list is inline@perl.org
612.PP
613To subscribe, send email to inline\-subscribe@perl.org
614.SH "BUGS AND DEFICIENCIES"
615.IX Header "BUGS AND DEFICIENCIES"
616.IP "1" 4
617.IX Item "1"
618If you use C function names that happen to be used internally by Perl,
619you will get a load error at run time. There is currently no
620functionality to prevent this or to warn you. For now, a list of Perl's
621internal symbols is packaged in the Inline module distribution under the
622filename \f(CW'symbols.perl'\fR. Avoid using these in your code.
623.SH "AUTHOR"
624.IX Header "AUTHOR"
625Brian Ingerson <INGY@cpan.org>
626.SH "COPYRIGHT"
627.IX Header "COPYRIGHT"
628Copyright (c) 2000, 2001, 2002. Brian Ingerson. All rights reserved.
629.PP
630This program is free software; you can redistribute it and/or modify it
631under the same terms as Perl itself.
632.PP
633See http://www.perl.com/perl/misc/Artistic.html