<?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: Effective C Tip #5 &#8211; Use pre-masking rather than post-masking</title>
	<atom:link href="http://embeddedgurus.com/stack-overflow/2009/08/effective-c-tip-5-use-pre-masking-rather-than-post-masking/feed/" rel="self" type="application/rss+xml" />
	<link>http://embeddedgurus.com/stack-overflow/2009/08/effective-c-tip-5-use-pre-masking-rather-than-post-masking/</link>
	<description>Thoughts on embedded systems by Nigel Jones</description>
	<lastBuildDate>Sun, 06 May 2012 10:34:02 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Nigel Jones</title>
		<link>http://embeddedgurus.com/stack-overflow/2009/08/effective-c-tip-5-use-pre-masking-rather-than-post-masking/comment-page-1/#comment-259</link>
		<dc:creator>Nigel Jones</dc:creator>
		<pubDate>Thu, 20 Aug 2009 15:54:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2009/08/17/effective-c-tip-5-use-pre-masking-rather-than-post-masking/#comment-259</guid>
		<description>Hi Steve:My general response is that I was trying to be illustrative and so omitted several &#039;real-world&#039; issues.Now to some specific responses.1. I have found plenty of real world scenarios where pre-masking works very well.2. If the particular case does require one to check for buffer full, then indeed pre-masking can make things more difficult. Having said that, I&#039;ll do a posting shortly concerning my experiences with run time error checking in embedded systems. I think you&#039;ll find my views slightly controversial...3. Your comment concerning volatile is mostly correct. Variables that are modified in an ISR should normally be declared volatile. There are however exceptions, which again I will address in another blog posting.</description>
		<content:encoded><![CDATA[<p>Hi Steve:My general response is that I was trying to be illustrative and so omitted several &#39;real-world&#39; issues.Now to some specific responses.1. I have found plenty of real world scenarios where pre-masking works very well.2. If the particular case does require one to check for buffer full, then indeed pre-masking can make things more difficult. Having said that, I&#39;ll do a posting shortly concerning my experiences with run time error checking in embedded systems. I think you&#39;ll find my views slightly controversial&#8230;3. Your comment concerning volatile is mostly correct. Variables that are modified in an ISR should normally be declared volatile. There are however exceptions, which again I will address in another blog posting.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: steve</title>
		<link>http://embeddedgurus.com/stack-overflow/2009/08/effective-c-tip-5-use-pre-masking-rather-than-post-masking/comment-page-1/#comment-258</link>
		<dc:creator>steve</dc:creator>
		<pubDate>Mon, 17 Aug 2009 13:25:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2009/08/17/effective-c-tip-5-use-pre-masking-rather-than-post-masking/#comment-258</guid>
		<description>But what if you need to check whether or not the buffer is full before writing to it?One method is to have a read index for the rx buffer (where RxHead is the write index), which is similarly incremented and wrapped when data is read out of the buffer elsewhere in the code.Any function which uses these two indices to determine if the buffer is full will need to deal with the special circumstance when the buffer wraps around, where the write index is 0, and the read index is RX_BUG_SIZE-1.However, with the suggested strategy, one (or both) indices could now also be RX_BUF_SIZE, which will make the buffer-is-full function more complex. I don&#039;t doubt that this could be done, but I wonder if it&#039;s worth the additional complexity.Put another way, this strategy is advocating that RxHead can have two values (0 and RX_BUF_SIZE) which both indicate a value of zero. If nothing else, this seems philosophically troubling!PS: Shouldn&#039;t Rx_Buf and RxHead both be declared as volatile, given that they are modified in an interrupt?</description>
		<content:encoded><![CDATA[<p>But what if you need to check whether or not the buffer is full before writing to it?One method is to have a read index for the rx buffer (where RxHead is the write index), which is similarly incremented and wrapped when data is read out of the buffer elsewhere in the code.Any function which uses these two indices to determine if the buffer is full will need to deal with the special circumstance when the buffer wraps around, where the write index is 0, and the read index is RX_BUG_SIZE-1.However, with the suggested strategy, one (or both) indices could now also be RX_BUF_SIZE, which will make the buffer-is-full function more complex. I don&#39;t doubt that this could be done, but I wonder if it&#39;s worth the additional complexity.Put another way, this strategy is advocating that RxHead can have two values (0 and RX_BUF_SIZE) which both indicate a value of zero. If nothing else, this seems philosophically troubling!PS: Shouldn&#39;t Rx_Buf and RxHead both be declared as volatile, given that they are modified in an interrupt?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

