Programming Perl in C
Perl's data types are like objects in another sense they support a lightweight
form of polymorphism. Polymorphism is the property of an object in a derived
class to behave like an object of a parent class. In this case the inheritance tree is
simple SV behaves as the parent class, and all the other types derive from SV. The
Perl internals exploit this by using function parameter and return types of SV* to
actually contain any of the available data types.
Scalar Values (SV)
The SV type represents a Perl scalar (that is, $scalar). A scalar may contain a signed
integer (IV), an unsigned integer (UV), a floating point number (NV), or a string
value (PV). These types are typedef aliases for fundamental C types. For example, IV
may be a typedef for int or long. NV is usually a typedef for double. You can find out
what the underlying types are on your system using the perl V switch. For example,
here's the output on my system:
$ perl V:ivtype V:uvtype V:nvtype
ivtype= long ;
uvtype= unsigned long ;
nvtype= double ;
Notice that PV wasn't included here that's because PV is always char * regardless
of the platform.
Perl uses aliases for C's fundamental types to improve portability; C's types
can differ wildly between platforms, but Perl's aliases maintain a modicum of con
sistency. Perl's IV and UV types are guaranteed to be at least 32 bits wide and large
enough to safely hold a pointer. For exact bit widths, Perl contains typedefs called
I8, U8, I16, U16, I32, and U32 that are guaranteed to be at least the size specified and
as small as possible.
Like all Perl data types, SV is an opaque type. An opaque type is one that you are
not intended to interact with directly. Instead, you call functions that operate on
the data type. This means that you should never dereference a pointer to a Perl
data type directly doing so exposes the underlying implementation of the data
type, which may change wildly between Perl versions.
Creation
The simplest way to create a new SV is with the NEWSV macro:
SV *sv = NEWSV(0,0);
17
177
7
footer
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