<?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/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	
	>
<channel>
	<title>
	Comments on: Function Poisoning in C++	</title>
	<atom:link href="https://www.fluentcpp.com/2018/09/04/function-poisoning-in-cpp/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.fluentcpp.com/2018/09/04/function-poisoning-in-cpp/</link>
	<description>Jonathan Boccara&#039;s blog</description>
	<lastBuildDate>Fri, 07 Dec 2018 18:46:00 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.5.3</generator>
	<item>
		<title>
		By: AndreyT		</title>
		<link>https://www.fluentcpp.com/2018/09/04/function-poisoning-in-cpp/#comment-1520</link>

		<dc:creator><![CDATA[AndreyT]]></dc:creator>
		<pubDate>Fri, 07 Dec 2018 18:46:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=4160#comment-1520</guid>

					<description><![CDATA[&#062; I do not think there are any valid use cases where to use any of the std::mem* functions. They can all be replaced by a standard algorithm or language construct [...]

Um... No, this is not true. One important detail about language-level initialization is that it is not guaranteed to do anything to padding bytes and padding bits that might (and typically will) be present in the target datatype. All these initialization methods leave padding bytes in indeterminate state.

This is OK for purely abstract language-level development, since values of padding bits/bytes are typically invisible at that level. 

However, the moment we drop to the level of binary byte-wise reinterpretation of our data, the padding suddenly begins to matter a lot. For example, if you send your object to a binary stream (a network protocol, a zipped file, a simple binary file) this padding begins to affect things in rather drastic and unpredictable ways. This is when you have to remember to keep you padding clean. And that&#039;s where there&#039;s no real alternative to `std::memset`.]]></description>
			<content:encoded><![CDATA[<p>&gt; I do not think there are any valid use cases where to use any of the std::mem* functions. They can all be replaced by a standard algorithm or language construct [&#8230;]</p>
<p>Um&#8230; No, this is not true. One important detail about language-level initialization is that it is not guaranteed to do anything to padding bytes and padding bits that might (and typically will) be present in the target datatype. All these initialization methods leave padding bytes in indeterminate state.</p>
<p>This is OK for purely abstract language-level development, since values of padding bits/bytes are typically invisible at that level. </p>
<p>However, the moment we drop to the level of binary byte-wise reinterpretation of our data, the padding suddenly begins to matter a lot. For example, if you send your object to a binary stream (a network protocol, a zipped file, a simple binary file) this padding begins to affect things in rather drastic and unpredictable ways. This is when you have to remember to keep you padding clean. And that&#8217;s where there&#8217;s no real alternative to `std::memset`.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: AndreyT		</title>
		<link>https://www.fluentcpp.com/2018/09/04/function-poisoning-in-cpp/#comment-1518</link>

		<dc:creator><![CDATA[AndreyT]]></dc:creator>
		<pubDate>Fri, 07 Dec 2018 09:35:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=4160#comment-1518</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2018/09/04/function-poisoning-in-cpp/#comment-1343&quot;&gt;Botet Escriba Vicente J.&lt;/a&gt;.

What are you talking about? Yes, you CAN &quot;reset&quot; an object by assigning a {} to it, assuming the object supports {} initializer.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2018/09/04/function-poisoning-in-cpp/#comment-1343">Botet Escriba Vicente J.</a>.</p>
<p>What are you talking about? Yes, you CAN &#8220;reset&#8221; an object by assigning a {} to it, assuming the object supports {} initializer.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Botet Escriba Vicente J.		</title>
		<link>https://www.fluentcpp.com/2018/09/04/function-poisoning-in-cpp/#comment-1343</link>

		<dc:creator><![CDATA[Botet Escriba Vicente J.]]></dc:creator>
		<pubDate>Sat, 29 Sep 2018 14:26:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=4160#comment-1343</guid>

					<description><![CDATA[Note that we can not use {} to reinitialize a type to zero, so even in C++11 the use of such a fillmem function is useful

foo f{};

// change f

//...

//f = {} // compile fails

fillmem(f);

BTW, I don&#039;t like the default value argument, I would prefer a zero_init function.

I&#039;ve a zero_initializer type that can be used as follows in C++98 for POD structs

foo f = zero_initializer();

This will perform a memset to 0 while doing the conversion from the zero_initializer to the type foo.]]></description>
			<content:encoded><![CDATA[<p>Note that we can not use {} to reinitialize a type to zero, so even in C++11 the use of such a fillmem function is useful</p>
<p>foo f{};</p>
<p>// change f</p>
<p>//&#8230;</p>
<p>//f = {} // compile fails</p>
<p>fillmem(f);</p>
<p>BTW, I don&#8217;t like the default value argument, I would prefer a zero_init function.</p>
<p>I&#8217;ve a zero_initializer type that can be used as follows in C++98 for POD structs</p>
<p>foo f = zero_initializer();</p>
<p>This will perform a memset to 0 while doing the conversion from the zero_initializer to the type foo.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Metrosian		</title>
		<link>https://www.fluentcpp.com/2018/09/04/function-poisoning-in-cpp/#comment-1274</link>

		<dc:creator><![CDATA[Metrosian]]></dc:creator>
		<pubDate>Wed, 05 Sep 2018 09:34:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=4160#comment-1274</guid>

					<description><![CDATA[Would you recommend use of the poison pragma over the use of a linter with rules to reject certain functions?]]></description>
			<content:encoded><![CDATA[<p>Would you recommend use of the poison pragma over the use of a linter with rules to reject certain functions?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Aki Jäntti		</title>
		<link>https://www.fluentcpp.com/2018/09/04/function-poisoning-in-cpp/#comment-1273</link>

		<dc:creator><![CDATA[Aki Jäntti]]></dc:creator>
		<pubDate>Wed, 05 Sep 2018 03:33:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=4160#comment-1273</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2018/09/04/function-poisoning-in-cpp/#comment-1268&quot;&gt;Joshua Brown&lt;/a&gt;.

#pragma GCC poison seems to work unmodified with clang.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2018/09/04/function-poisoning-in-cpp/#comment-1268">Joshua Brown</a>.</p>
<p>#pragma GCC poison seems to work unmodified with clang.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Aki Jäntti		</title>
		<link>https://www.fluentcpp.com/2018/09/04/function-poisoning-in-cpp/#comment-1272</link>

		<dc:creator><![CDATA[Aki Jäntti]]></dc:creator>
		<pubDate>Wed, 05 Sep 2018 02:41:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=4160#comment-1272</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2018/09/04/function-poisoning-in-cpp/#comment-1269&quot;&gt;Aki Jäntti&lt;/a&gt;.

Trying to get a user friendly portable way gets a bit more involved because of macro expanding pragmas and string literals, but at least clang seems to support GCC poison directly, so this worked for me<img src="https://s.w.org/images/core/emoji/15.0.3/72x72/2122.png" alt="™" class="wp-smiley" style="height: 1em; max-height: 1em;" />:

#define PPSTRINGIFY2(X) #X
#define PPSTRINGIFY(X) PPSTRINGIFY2(X)

#if defined(__GNUC__) &#124;&#124; defined(__clang__)
#define PRAGMA_POISON(x) _Pragma(PPSTRINGIFY(GCC poison x))
#elif _MSC_VER
#define PRAGMA_POISON(x) __pragma (deprecated(#x))
#endif
 
PRAGMA_POISON(malloc)]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2018/09/04/function-poisoning-in-cpp/#comment-1269">Aki Jäntti</a>.</p>
<p>Trying to get a user friendly portable way gets a bit more involved because of macro expanding pragmas and string literals, but at least clang seems to support GCC poison directly, so this worked for me™:</p>
<p>#define PPSTRINGIFY2(X) #X<br />
#define PPSTRINGIFY(X) PPSTRINGIFY2(X)</p>
<p>#if defined(__GNUC__) || defined(__clang__)<br />
#define PRAGMA_POISON(x) _Pragma(PPSTRINGIFY(GCC poison x))<br />
#elif _MSC_VER<br />
#define PRAGMA_POISON(x) __pragma (deprecated(#x))<br />
#endif</p>
<p>PRAGMA_POISON(malloc)</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Aki Jäntti		</title>
		<link>https://www.fluentcpp.com/2018/09/04/function-poisoning-in-cpp/#comment-1269</link>

		<dc:creator><![CDATA[Aki Jäntti]]></dc:creator>
		<pubDate>Wed, 05 Sep 2018 02:03:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=4160#comment-1269</guid>

					<description><![CDATA[In MSVC there is #pragma deprecated(&quot;token&quot; )
It needs quotes if you want to deprecate macros before expansion. Or without quotes to deprecate things after macro expansion, I guess, but you should have those deprecations as the first thing anyway. 
And also some others like __declspec(deprecated(&quot;optional message&quot;)) and [[deprecated]] 

It&#039;s supposed to give a warning instead of error, but treating warnings as errors is pretty good policy anyway. Alternatively you can turn it into an error with #pragma warning(error: 4995)
Or... at least it&#039;s supposed to be a warning, but in my quick test with newest MSVC it apparently throws an error by default.]]></description>
			<content:encoded><![CDATA[<p>In MSVC there is #pragma deprecated(&#8220;token&#8221; )<br />
It needs quotes if you want to deprecate macros before expansion. Or without quotes to deprecate things after macro expansion, I guess, but you should have those deprecations as the first thing anyway.<br />
And also some others like __declspec(deprecated(&#8220;optional message&#8221;)) and [[deprecated]] </p>
<p>It&#8217;s supposed to give a warning instead of error, but treating warnings as errors is pretty good policy anyway. Alternatively you can turn it into an error with #pragma warning(error: 4995)<br />
Or&#8230; at least it&#8217;s supposed to be a warning, but in my quick test with newest MSVC it apparently throws an error by default.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Joshua Brown		</title>
		<link>https://www.fluentcpp.com/2018/09/04/function-poisoning-in-cpp/#comment-1268</link>

		<dc:creator><![CDATA[Joshua Brown]]></dc:creator>
		<pubDate>Tue, 04 Sep 2018 15:21:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=4160#comment-1268</guid>

					<description><![CDATA[I have a question: Do you know if there is a pragma command for clang that will do something similar?]]></description>
			<content:encoded><![CDATA[<p>I have a question: Do you know if there is a pragma command for clang that will do something similar?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: jft		</title>
		<link>https://www.fluentcpp.com/2018/09/04/function-poisoning-in-cpp/#comment-1267</link>

		<dc:creator><![CDATA[jft]]></dc:creator>
		<pubDate>Tue, 04 Sep 2018 11:31:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=4160#comment-1267</guid>

					<description><![CDATA[For MS VS, this is not a complete replacement for gcc poison, but you can do something like

#include 
using namespace std;
 
int main()
{
	const size_t sz = 7;
 
	char str[sz];
 
	memset(str, 2, sz);	// This is OK
 
#define memset()
 
	memset(str, 3, sz);	// This fails to compile with too many arguments error because of macro definition
 
#undef memset
 
	memset(str, 3, sz);	// This is OK as macro definition now removed
}

using #define to redefine a name as a macro you want to stop being used so that you get a compiler error

1&#062;c:developvctest12test12test12.cpp(16): warning C4002: too many arguments for function-like macro invocation &#039;memset&#039;

In some ways this is better than gcc poison as you can define/undefine the macro as needed in the code whereas as stated above, once poisoned there is no antidote!]]></description>
			<content:encoded><![CDATA[<p>For MS VS, this is not a complete replacement for gcc poison, but you can do something like</p>
<p>#include<br />
using namespace std;</p>
<p>int main()<br />
{<br />
	const size_t sz = 7;</p>
<p>	char str[sz];</p>
<p>	memset(str, 2, sz);	// This is OK</p>
<p>#define memset()</p>
<p>	memset(str, 3, sz);	// This fails to compile with too many arguments error because of macro definition</p>
<p>#undef memset</p>
<p>	memset(str, 3, sz);	// This is OK as macro definition now removed<br />
}</p>
<p>using #define to redefine a name as a macro you want to stop being used so that you get a compiler error</p>
<p>1&gt;c:developvctest12test12test12.cpp(16): warning C4002: too many arguments for function-like macro invocation &#8216;memset&#8217;</p>
<p>In some ways this is better than gcc poison as you can define/undefine the macro as needed in the code whereas as stated above, once poisoned there is no antidote!</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
