Imported Upstream version 2.50.2
[platform/upstream/glib.git] / docs / reference / gobject / html / chapter-intro.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <title>Background: GObject Reference Manual</title>
6 <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7 <link rel="home" href="index.html" title="GObject Reference Manual">
8 <link rel="up" href="pt01.html" title="Part I. Concepts">
9 <link rel="prev" href="pt01.html" title="Part I. Concepts">
10 <link rel="next" href="ch01s02.html" title="Exporting a C API">
11 <meta name="generator" content="GTK-Doc V1.25.1 (XML mode)">
12 <link rel="stylesheet" href="style.css" type="text/css">
13 </head>
14 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
15 <table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="5"><tr valign="middle">
16 <td width="100%" align="left" class="shortcuts"></td>
17 <td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
18 <td><a accesskey="u" href="pt01.html"><img src="up.png" width="16" height="16" border="0" alt="Up"></a></td>
19 <td><a accesskey="p" href="pt01.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
20 <td><a accesskey="n" href="ch01s02.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
21 </tr></table>
22 <div class="chapter">
23 <div class="titlepage"><div><div><h2 class="title">
24 <a name="chapter-intro"></a>Background</h2></div></div></div>
25 <div class="toc"><dl class="toc">
26 <dt><span class="sect1"><a href="chapter-intro.html#id-1.3.2.5">Data types and programming</a></span></dt>
27 <dt><span class="sect1"><a href="ch01s02.html">Exporting a C API</a></span></dt>
28 </dl></div>
29 <p>
30     GObject, and its lower-level type system, GType, are used by GTK+ and most GNOME libraries to
31     provide:
32     </p>
33 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
34 <li class="listitem"><p>object-oriented C-based APIs and</p></li>
35 <li class="listitem"><p>automatic transparent API bindings to other compiled 
36       or interpreted languages.</p></li>
37 </ul></div>
38 <p>
39   </p>
40 <p>
41     A lot of programmers are used to working with compiled-only or dynamically interpreted-only
42     languages and do not understand the challenges associated with cross-language interoperability.
43     This introduction tries to provide an insight into these challenges and briefly describes
44     the solution chosen by GLib.
45   </p>
46 <p>
47     The following chapters go into greater detail into how GType and GObject work and
48     how you can use them as a C programmer. It is useful to keep in mind that
49     allowing access to C objects from other interpreted languages was one of the major design
50     goals: this can often explain the sometimes rather convoluted APIs and features present
51     in this library.
52   </p>
53 <div class="sect1">
54 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
55 <a name="id-1.3.2.5"></a>Data types and programming</h2></div></div></div>
56 <p>
57       One could say
58       that a programming language is merely a way to create data types and manipulate them. Most languages
59       provide a number of language-native types and a few primitives to create more complex types based
60       on these primitive types.
61     </p>
62 <p>
63       In C, the language provides types such as <span class="emphasis"><em>char</em></span>, <span class="emphasis"><em>long</em></span>, 
64       <span class="emphasis"><em>pointer</em></span>. During compilation of C code, the compiler maps these
65       language types to the compiler's target architecture machine types. If you are using a C interpreter
66       (assuming one exists), the interpreter (the program which interprets 
67       the source code and executes it) maps the language types to the machine types of the target machine at 
68       runtime, during the program execution (or just before execution if it uses a Just In Time compiler engine).
69     </p>
70 <p>
71       Perl and Python are interpreted languages which do not really provide type definitions similar
72       to those used by C. Perl and Python programmers manipulate variables and the type of the variables
73       is decided only upon the first assignment or upon the first use which forces a type on the variable.
74       The interpreter also often provides a lot of automatic conversions from one type to the other. For example,
75       in Perl, a variable which holds an integer can be automatically converted to a string given the
76       required context:
77 </p>
78 <div class="informalexample">
79   <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
80     <tbody>
81       <tr>
82         <td class="listing_lines" align="right"><pre>1
83 2</pre></td>
84         <td class="listing_code"><pre class="programlisting">my $tmp <span class="gtkdoc opt">=</span> <span class="number">10</span><span class="gtkdoc opt">;</span>
85 print <span class="string">&quot;this is an integer converted to a string:&quot;</span> <span class="gtkdoc opt">.</span> $tmp <span class="gtkdoc opt">.</span> <span class="string">&quot;</span><span class="gtkdoc esc">\n</span><span class="string">&quot;</span><span class="gtkdoc opt">;</span></pre></td>
86       </tr>
87     </tbody>
88   </table>
89 </div>
90
91 <p>
92       Of course, it is also often possible to explicitly specify conversions when the default conversions provided
93       by the language are not intuitive.
94     </p>
95 </div>
96 </div>
97 <div class="footer">
98 <hr>Generated by GTK-Doc V1.25.1</div>
99 </body>
100 </html>