1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
<html>
<head>
<title>EAGLE Help: Variable Definitions</title>
</head>
<body bgcolor=white>
<font face=Helvetica,Arial>
<hr>
<i>EAGLE Help</i>
<h1><center>Variable Definitions</center></h1>
<hr>
The general syntax of a <i>variable definition</i> is
<pre>
[numeric] type identifier [= initializer][, ...];
</pre>
where <tt>type</tt> is one of the
<a href=154.htm>data</a> or
<a href=161.htm>object types</a>,
<tt>identifier</tt> is the name of the variable, and <tt>initializer</tt>
is a optional initial value.
<p>
Multiple variable definitions of the same <tt>type</tt> are separated
by commas (<tt>,</tt>).
<p>
If <tt>identifier</tt> is followed by a pair of
<a href=147.htm>brackets</a> (<tt>[]</tt>), this defines an array
of variables of the given <tt>type</tt>. The size of an array is
automatically adjusted at runtime.
<p>
The optional keyword <tt>numeric</tt> can be used with
<a href=158.htm>string</a> arrays to have them sorted
alphanumerically by the <a href=251.htm>sort()</a> function.
<p>
By default (if no <tt>initializer</tt> is present),
<a href=154.htm>data variables</a> are set to <tt>0</tt>
(or <tt>""</tt>, in case of a string), and
<a href=161.htm>object variables</a> are "invalid".
<p>
<b>Examples</b>
<p>
<table>
<tr><td valign=top><font face=Helvetica,Arial><tt>int i;</tt> </font></td><td valign=top><font face=Helvetica,Arial>defines an <a href=156.htm>int</a> variable named <tt>i</tt></font></td></tr>
<tr><td valign=top><font face=Helvetica,Arial><tt>string s = "Hello";</tt> </font></td><td valign=top><font face=Helvetica,Arial>defines a <a href=158.htm>string</a> variable named <tt>s</tt> and initializes it to <tt>"Hello"</tt></font></td></tr>
<tr><td valign=top><font face=Helvetica,Arial><tt>real a, b = 1.0, c;</tt> </font></td><td valign=top><font face=Helvetica,Arial>defines three <a href=157.htm>real</a> variables named <tt>a</tt>, <tt>b</tt> and <tt>c</tt>, initializing <tt>b</tt> to the value <tt>1.0</tt></font></td></tr>
<tr><td valign=top><font face=Helvetica,Arial><tt>int n[] = { 1, 2, 3 };</tt> </font></td><td valign=top><font face=Helvetica,Arial>defines an array of <a href=156.htm>int</a>, initializing the first three elements to <tt>1</tt>, <tt>2</tt> and <tt>3</tt></font></td></tr>
<tr><td valign=top><font face=Helvetica,Arial><tt>numeric string names[];</tt> </font></td><td valign=top><font face=Helvetica,Arial>defines a <a href=158.htm>string</a> array that can be sorted alphanumerically</font></td></tr>
<tr><td valign=top><font face=Helvetica,Arial><tt>UL_WIRE w;</tt> </font></td><td valign=top><font face=Helvetica,Arial>defines a <a href=196.htm>UL_WIRE</a> object named <tt>w</tt></font></td></tr>
</table>
The members of array elements of <a href=161.htm>objekt types</a> can't be accessed directly:
<pre>
UL_SIGNAL signals[];
...
UL_SIGNAL s = signals[0];
printf("%s", s.name);
</pre>
<hr>
<table width=100% cellspacing=0 border=0><tr><td align=left><font face=Helvetica,Arial>
<a href=index.htm>Index</a>
</font></td><td align=right><font face=Helvetica,Arial size=-1>
<i>Copyright © 2005 CadSoft Computer GmbH</i>
</font></td></tr></table>
<hr>
</font>
</body>
</html>
|