<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>语源科技BlogJava-faintbear</title><link>http://www.blogjava.net/faintbear/</link><description>小风嗖嗖的刮着......</description><language>zh-cn</language><lastBuildDate>Wed, 15 Jul 2026 11:45:00 GMT</lastBuildDate><pubDate>Wed, 15 Jul 2026 11:45:00 GMT</pubDate><ttl>60</ttl><item><title>静态局部变量</title><link>http://www.blogjava.net/faintbear/archive/2010/01/06/308408.html</link><dc:creator>小力力力</dc:creator><author>小力力力</author><pubDate>Wed, 06 Jan 2010 03:37:00 GMT</pubDate><guid>http://www.blogjava.net/faintbear/archive/2010/01/06/308408.html</guid><wfw:comment>http://www.blogjava.net/faintbear/comments/308408.html</wfw:comment><comments>http://www.blogjava.net/faintbear/archive/2010/01/06/308408.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/faintbear/comments/commentRss/308408.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/faintbear/services/trackbacks/308408.html</trackback:ping><description><![CDATA[在局部变量前加上&#8220;static&#8221;关键字，就成了静态局部变量。静态局部变量存放在内存的全局数据区。函数结束时，静态局部变量不会消失，每次该函数调用
时，也不会为其重新分配空间。它始终驻留在全局数据区，直到程序运行结束。静态局部变量的初始化与全局变量类似．如果不为其显式初始化，则C++自动为其
初始化为0。<br />
静态局部变量与全局变量共享全局数据区，但静态局部变量只在定义它的函数中可见。静态局部变量与局部变量在存储位置上不同，使得其存在的时限也不同，导致对这两者操作 的运行结果也不同。<br />
例如，下面的程序定义了全局变量、静态局部变量和局部变量：<br />
<span class="ff0000"><font color="#ff0000">　//*********************<br />
//**　　 ch5_2.cpp　 **<br />
//********************* </font></span>
<p class="ff0000"><font color="#ff0000">　　　　#include &lt;iostream.h&gt;</font></p>
<p class="ff0000"><font color="#ff0000">　　　　void func();<br />
int n=1; //全局变量</font></p>
<p class="ff0000"><font color="#ff0000">　　　　void main()<br />
{<br />
<em><strong>static</strong></em> int a; // 静态局部变量<br />
int b= -10; // 局部变量<br />
cout &lt;&lt;"a:" &lt;&lt;a<br />
&lt;&lt;" b:" &lt;&lt;b<br />
&lt;&lt;" n:" &lt;&lt;n &lt;&lt;endl;<br />
b+=4;<br />
func();<br />
cout &lt;&lt;"a:" &lt;&lt;a<br />
&lt;&lt;" b:" &lt;&lt;b<br />
&lt;&lt;" n:" &lt;&lt;n &lt;&lt;endl;<br />
n+=10;<br />
func();<br />
}</font></p>
<p class="ff0000"><font color="#ff0000">　　　　void func()<br />
{<br />
<em><strong>static</strong></em> int a=2; // 静态局部变量<br />
int b=5; // 局部变量<br />
a+=2;<br />
n+=12;<br />
b+=5;<br />
cout &lt;&lt;"a:" &lt;&lt;a<br />
&lt;&lt;" b:" &lt;&lt;b<br />
&lt;&lt;" n:" &lt;&lt;n &lt;&lt;endl;<br />
}</font></p>
<p class="p14">　　运行结果为：<br />
<span class="ff0000">　　　<font color="#ff0000">　a:0 b:-10 n:l<br />
a:4 b:10 n:13<br />
a:0 b:-6 n:13<br />
a:6 b:10 n:35</font></span><br />
程序中主函数main()两次调用了func()函数，从运行结果可以看出，程序控制每次进入func()函数时，局部变量b都被初始化。而静态局部
变量a仅在第一次调用时被初始化，第二次进入该函数时，不再进行初始化，这时它的值是第一次调用后的结果值4。
main()函数中的变量a和b与func()函数中的变量a和b空间位置是不一样的，所以相应的值也不一样。关于变量作用域和可见性的进一步讨论见第6
章。<br />
静态局部变量的用途有许多：可以使用它确定某函数是否被调用过。使用它保留多次调用的值。</p>
<p class="p14"><strong><font size="5">对静态局部变量的说明：</font></strong> <br />
(1) 静态局部变量在静态存储区内分配存储单元。在程序整个运行期间都不释放。而自动变量（即动态局部变量）属于动态存储类别，存储在动态存储区空间(而不是静态存储区空间)，函数调用结束后即释放。 <br />
(2)
为静态局部变量赋初值是在编译时进行值的，即只赋初值一次，在程序运行时它已有初值。以后每次调用函数时不再重新赋初值而只是保留上次函数调用结束时的
值。而为自动变量赋初值，不是在编译时进行的，而是在函数调用时进行，每调用一次函数重新给一次初值，相当于执行一次赋值语句。 <br />
<br />
(3)
如果在定义局部变量时不赋初值的话，对静态局部变量来说，编译时自动赋初值0(对数值型变量)或空字符(对字符型变量)。而对自动变量来说，如果不赋初
值，则它的值是一个不确定的值。这是由于每次函数调用结束后存储单元已释放，下次调用时又重新另分配存储单元，而所分配的单元中的值是不确定的。 <br />
(4) 虽然静态局部变量在函数调用结束后仍然存在，但其他函数是不能引用它的，也就是说，在其他函数中它是&#8220;不可见&#8221;的。</p>
<img src ="http://www.blogjava.net/faintbear/aggbug/308408.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/faintbear/" target="_blank">小力力力</a> 2010-01-06 11:37 <a href="http://www.blogjava.net/faintbear/archive/2010/01/06/308408.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>走近GPRS</title><link>http://www.blogjava.net/faintbear/archive/2006/09/07/68215.html</link><dc:creator>小力力力</dc:creator><author>小力力力</author><pubDate>Thu, 07 Sep 2006 03:45:00 GMT</pubDate><guid>http://www.blogjava.net/faintbear/archive/2006/09/07/68215.html</guid><wfw:comment>http://www.blogjava.net/faintbear/comments/68215.html</wfw:comment><comments>http://www.blogjava.net/faintbear/archive/2006/09/07/68215.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/faintbear/comments/commentRss/68215.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/faintbear/services/trackbacks/68215.html</trackback:ping><description><![CDATA[
		<table width="680" align="center">
				<tbody>
						<tr>
								<td align="middle">
										<h2>
												<font color="#0f3ccd">走近GPRS</font>
										</h2>
										<br />
										<b>崔绘</b>
										<br />
										<hr width="660" color="#f46240" size="1" />
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<table width="620" align="center">
				<tbody>
						<tr>
								<td class="a14">
								</td>
						</tr>
				</tbody>
		</table>
		<table width="620" align="center">
				<tbody>
						<tr>
								<td class="a14">
								</td>
						</tr>
				</tbody>
		</table>
		<table width="620" align="center">
				<tbody>
						<tr>
								<td class="a14">对于一个技术人员而言，GPRS是一个美丽而又复杂的系统，它继承了无线领域几代技术的精华，又吸收了数据网络数十年成功的经验。如此种种，决非一篇文章可以尽数。本文试图从原理角度介绍GPRS网络元素、数据传输协议和操作流程，希望能揭开冰山的一角，为大家了解GPRS技术提供帮助。 </td>
						</tr>
				</tbody>
		</table>
		<table width="620" align="center">
				<tbody>
						<tr>
								<td class="a14">
								</td>
						</tr>
				</tbody>
		</table>
		<table width="620" align="center">
				<tbody>
						<tr>
								<td class="a14">作为一个用户，他所见到GPRS网络是一个承载网，与以太网，帧中继网无异。而从系统工程师的角度看，这个网络就复杂多了，为了提供二层承载，GPRS网络引入了许多新的网络元素和数据处理方法。 </td>
						</tr>
				</tbody>
		</table>
		<table width="620" align="center">
				<tbody>
						<tr>
								<td class="a14">
								</td>
						</tr>
				</tbody>
		</table>
		<table width="620" align="center">
				<tbody>
						<tr>
								<td class="a14">数据由用户的手机到因特网要经过四个设备，MS（Mobile Station，手机）、BSS（Base Station System，基站系统）、SGSN（Serving GPRS Support Node，服务GPRS节点）和GGSN（Gateway GPRS Support Node，网关GPRS节点）。其中，SGSN和GGSN是新增设备，而MS和BSS需要进行设备的软硬件升级。 </td>
						</tr>
				</tbody>
		</table>
		<table width="620" align="center">
				<tbody>
						<tr>
								<td class="a14">
								</td>
						</tr>
				</tbody>
		</table>
		<table width="620" align="center">
				<tbody>
						<tr>
								<td class="a14">它们的主要功能如下： </td>
						</tr>
				</tbody>
		</table>
		<table width="620" align="center">
				<tbody>
						<tr>
								<td class="a14">
								</td>
						</tr>
				</tbody>
		</table>
		<table width="620" align="center">
				<tbody>
						<tr>
								<td class="a14">MS：一方面，处理空中接口的上下行传输；另一方面，将数据信息发给与之连接的计算机。 </td>
						</tr>
				</tbody>
		</table>
		<table width="620" align="center">
				<tbody>
						<tr>
								<td class="a14">
								</td>
						</tr>
				</tbody>
		</table>
		<table width="620" align="center">
				<tbody>
						<tr>
								<td class="a14">BSS：通常包括一系列设备。负责分配空中的信道资源，并在手机和SGSN之间转发信息。 </td>
						</tr>
				</tbody>
		</table>
		<table width="620" align="center">
				<tbody>
						<tr>
								<td class="a14">
								</td>
						</tr>
				</tbody>
		</table>
		<table width="620" align="center">
				<tbody>
						<tr>
								<td class="a14">SGSN：是无线部分和数据网部分的分界线，负责管理手机的移动，并与GGSN协作完成用户数据在Gn网络上的传输。 </td>
						</tr>
				</tbody>
		</table>
		<table width="620" align="center">
				<tbody>
						<tr>
								<td class="a14">
								</td>
						</tr>
				</tbody>
		</table>
		<table width="620" align="center">
				<tbody>
						<tr>
								<td class="a14">GGSN：是GPRS网络与外网的分界线，对内负责Gn网络的传输，对外是一台因特网路由器。其中的BGGSN（Border GGSN）负责连接不同运营商之间的Gn网络，实现网间漫游。上述四个设备将用户的计算机和因特网连接起来，完成了无线上网的数据传输工作。这之间用到的接口有： </td>
						</tr>
				</tbody>
		</table>
		<table width="620" align="center">
				<tbody>
						<tr>
								<td class="a14">
								</td>
						</tr>
				</tbody>
		</table>
		<table width="620" align="center">
				<tbody>
						<tr>
								<td class="a14">R：计算机与GPRS手机之间的接口。可以基于多种传输方法，如RS232、红外等等。 </td>
						</tr>
				</tbody>
		</table>
		<table width="620" align="center">
				<tbody>
						<tr>
								<td class="a14">
								</td>
						</tr>
				</tbody>
		</table>
		<table width="620" align="center">
				<tbody>
						<tr>
								<td class="a14">Um：空中接口，在手机与BSS之间。接口上的传输格式与GSM无异，但逻辑信道的定义和分配有很大差别。 </td>
						</tr>
				</tbody>
		</table>
		<table width="620" align="center">
				<tbody>
						<tr>
								<td class="a14">
								</td>
						</tr>
				</tbody>
		</table>
		<table width="620" align="center">
				<tbody>
						<tr>
								<td class="a14">Gb：BSS和SGSN之间的接口。可以是租用的帧中继网络或者是运行帧中继封装协议的专线。 </td>
						</tr>
				</tbody>
		</table>
		<table width="620" align="center">
				<tbody>
						<tr>
								<td class="a14">
								</td>
						</tr>
				</tbody>
		</table>
		<table width="620" align="center">
				<tbody>
						<tr>
								<td class="a14">Gn：SGSN和GGSN之间的接口。所有的SGSN和GGSN构成了GPRS的骨干网，这个网络是运营商的私有网络，与外网之间没有路由。GGSN将外网的信息封装后在Gn