<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Arduino Pointers and the Ping for Automated High Five</title>
	<atom:link href="http://www.uchobby.com/index.php/2009/08/17/arduino-pointers-and-the-ping-for-automated-high-five/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.uchobby.com/index.php/2009/08/17/arduino-pointers-and-the-ping-for-automated-high-five/</link>
	<description>Microcontrollers Electronics Hobby</description>
	<lastBuildDate>Tue, 24 Jan 2012 09:58:33 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: signal7</title>
		<link>http://www.uchobby.com/index.php/2009/08/17/arduino-pointers-and-the-ping-for-automated-high-five/comment-page-1/#comment-2159</link>
		<dc:creator>signal7</dc:creator>
		<pubDate>Tue, 18 Aug 2009 14:19:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.uchobby.com/index.php/2009/08/17/arduino-pointers-and-the-ping-for-automated-high-five/#comment-2159</guid>
		<description>While this is a good introduction to pointers, it doesn&#039;t mention the best feature of using pointers: arithmetic.

If you declare an array of type int, what you are really doing is creating a pointer to a location in memory that consists of a sequence of 4 byte blocks (because int&#039;s are typically 4 bytes to most* compilers).  You can then reference the elements of the array using simple addition and subtraction.  array[3] is the same as *(array + 3).  I know that might seem confusing, but the compiler knows the type of the array and also knows that each element is 4 bytes so when you add some number to the pointer, the compiler internally computes array + (3 * 4) to arrive at the correct address.

This might not seem useful - I&#039;ll grant you that.  However, when you start using arrays of structs or other more complicated data structures, this will be holy grail of understanding the usefulness of pointers.   Maybe it&#039;s overkill for the arduino environment, but with these AVR parts coming with more and more memory, I&#039;m sure more data processing applications will be coming.

* I say most compilers because there is no guarantee that an int is 4 bytes and you can&#039;t really depend on it being 4 bytes if you want to write reliable code.  If you really need a 4 byte int, use int32 instead.</description>
		<content:encoded><![CDATA[<p>While this is a good introduction to pointers, it doesn&#8217;t mention the best feature of using pointers: arithmetic.</p>
<p>If you declare an array of type int, what you are really doing is creating a pointer to a location in memory that consists of a sequence of 4 byte blocks (because int&#8217;s are typically 4 bytes to most* compilers).  You can then reference the elements of the array using simple addition and subtraction.  array[3] is the same as *(array + 3).  I know that might seem confusing, but the compiler knows the type of the array and also knows that each element is 4 bytes so when you add some number to the pointer, the compiler internally computes array + (3 * 4) to arrive at the correct address.</p>
<p>This might not seem useful &#8211; I&#8217;ll grant you that.  However, when you start using arrays of structs or other more complicated data structures, this will be holy grail of understanding the usefulness of pointers.   Maybe it&#8217;s overkill for the arduino environment, but with these AVR parts coming with more and more memory, I&#8217;m sure more data processing applications will be coming.</p>
<p>* I say most compilers because there is no guarantee that an int is 4 bytes and you can&#8217;t really depend on it being 4 bytes if you want to write reliable code.  If you really need a 4 byte int, use int32 instead.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

