<?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: Compile-Time Strings</title>
	<atom:link href="http://entland.homelinux.com/blog/2009/04/28/compile-time-strings/feed/" rel="self" type="application/rss+xml" />
	<link>http://entland.homelinux.com/blog/2009/04/28/compile-time-strings/</link>
	<description>Code, 3D, Games, Linux and much more...</description>
	<lastBuildDate>Mon, 09 Nov 2009 03:12:38 +0100</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Daniel "NeoStrider" Monteiro</title>
		<link>http://entland.homelinux.com/blog/2009/04/28/compile-time-strings/comment-page-1/#comment-171525</link>
		<dc:creator>Daniel "NeoStrider" Monteiro</dc:creator>
		<pubDate>Wed, 24 Jun 2009 02:32:25 +0000</pubDate>
		<guid isPermaLink="false">http://entland.homelinux.com/blog/?p=346#comment-171525</guid>
		<description>actually, the C standard defines that &quot;inline&quot; doesnt enforce the function to necessarily be inline. It only &quot;hints&quot; the compiler that it is a good candidate for inline function</description>
		<content:encoded><![CDATA[<p>actually, the C standard defines that &#8220;inline&#8221; doesnt enforce the function to necessarily be inline. It only &#8220;hints&#8221; the compiler that it is a good candidate for inline function</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ent</title>
		<link>http://entland.homelinux.com/blog/2009/04/28/compile-time-strings/comment-page-1/#comment-168588</link>
		<dc:creator>ent</dc:creator>
		<pubDate>Mon, 04 May 2009 10:59:13 +0000</pubDate>
		<guid isPermaLink="false">http://entland.homelinux.com/blog/?p=346#comment-168588</guid>
		<description>Gus,

yes, we have static functions that can be invoked from the watch window of the debugger:

&lt;pre lang=&quot;cpp&quot;&gt;
// These functions are to be used from the debugger Watch Window to 
// convert symbols to strings and vice versa while debugging.
// Use the following syntax in Microsoft Visual Studio:
//
//  {,,Debug.Core.Kernel.dll}SymbolToString(1146)
//  {,,Debug.Core.Kernel.dll}StringToSymbol(L&quot;DiskFileSystem&quot;)
//@{
extern &quot;C&quot; NS_CORE_KERNEL_API const NsChar* NsSymbolToString(NsSize id);
extern &quot;C&quot; NS_CORE_KERNEL_API NsSize NsStringToSymbol(const NsChar* str);
//@}
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Gus,</p>
<p>yes, we have static functions that can be invoked from the watch window of the debugger:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">// These functions are to be used from the debugger Watch Window to </span>
<span style="color: #666666;">// convert symbols to strings and vice versa while debugging.</span>
<span style="color: #666666;">// Use the following syntax in Microsoft Visual Studio:</span>
<span style="color: #666666;">//</span>
<span style="color: #666666;">//  {,,Debug.Core.Kernel.dll}SymbolToString(1146)</span>
<span style="color: #666666;">//  {,,Debug.Core.Kernel.dll}StringToSymbol(L&quot;DiskFileSystem&quot;)</span>
<span style="color: #666666;">//@{</span>
<span style="color: #0000ff;">extern</span> <span style="color: #FF0000;">&quot;C&quot;</span> NS_CORE_KERNEL_API <span style="color: #0000ff;">const</span> NsChar<span style="color: #000040;">*</span> NsSymbolToString<span style="color: #008000;">&#40;</span>NsSize id<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">extern</span> <span style="color: #FF0000;">&quot;C&quot;</span> NS_CORE_KERNEL_API NsSize NsStringToSymbol<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> NsChar<span style="color: #000040;">*</span> str<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #666666;">//@}</span></pre></div></div>

]]></content:encoded>
	</item>
	<item>
		<title>By: ent</title>
		<link>http://entland.homelinux.com/blog/2009/04/28/compile-time-strings/comment-page-1/#comment-168587</link>
		<dc:creator>ent</dc:creator>
		<pubDate>Mon, 04 May 2009 10:56:37 +0000</pubDate>
		<guid isPermaLink="false">http://entland.homelinux.com/blog/?p=346#comment-168587</guid>
		<description>Hi pizzi,

we try to avoid statics in our architecture. That way, we have under control the init order of the different subsystems (for example, the symbol system depends on the log system and memory system).

If you do not have that restriction, your solution seems to be right.</description>
		<content:encoded><![CDATA[<p>Hi pizzi,</p>
<p>we try to avoid statics in our architecture. That way, we have under control the init order of the different subsystems (for example, the symbol system depends on the log system and memory system).</p>
<p>If you do not have that restriction, your solution seems to be right.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rickyah</title>
		<link>http://entland.homelinux.com/blog/2009/04/28/compile-time-strings/comment-page-1/#comment-168585</link>
		<dc:creator>Rickyah</dc:creator>
		<pubDate>Mon, 04 May 2009 07:57:32 +0000</pubDate>
		<guid isPermaLink="false">http://entland.homelinux.com/blog/?p=346#comment-168585</guid>
		<description>Gus, I&#039;ve implemented that using #defines for debug configurations in VS.

My Symbol class has a string field and a constructor requiring the string, that are only visible when the _DEBUG symbol is defined:

class Symbol
{
public:
#if _DEBUG
	Symbol(size_t id, char* str) 
	{ 
		_id=id; 
		_str = str;
	}

	std::string getStr()
	{
		return _str;
	}
#else
	Symbol(size_t id) { _id=id; }
#endif
	size_t getID() { return _id; }
	
private:
#if _DEBUG
	const char* _str;
#endif
	size_t _id;
};

so you could use:
...
return Symbol(sym, #id); /
...

I&#039;ve just realized that a cleaner approach could be leaving that constructor and field available for all configurations, but saving the string only in debug, something like this:
Symbol::Symbol(u32 sym, char * str)
{
  _sym = sym;
#if _DEBUG
  _str = str;
#else
  _str = 0;
#endif
}

const char * Symbol::getStr()
{
   if (!_str) return &quot;&quot;; 
   return _str;
}</description>
		<content:encoded><![CDATA[<p>Gus, I&#8217;ve implemented that using #defines for debug configurations in VS.</p>
<p>My Symbol class has a string field and a constructor requiring the string, that are only visible when the _DEBUG symbol is defined:</p>
<p>class Symbol<br />
{<br />
public:<br />
#if _DEBUG<br />
	Symbol(size_t id, char* str)<br />
	{<br />
		_id=id;<br />
		_str = str;<br />
	}</p>
<p>	std::string getStr()<br />
	{<br />
		return _str;<br />
	}<br />
#else<br />
	Symbol(size_t id) { _id=id; }<br />
#endif<br />
	size_t getID() { return _id; }</p>
<p>private:<br />
#if _DEBUG<br />
	const char* _str;<br />
#endif<br />
	size_t _id;<br />
};</p>
<p>so you could use:<br />
&#8230;<br />
return Symbol(sym, #id); /<br />
&#8230;</p>
<p>I&#8217;ve just realized that a cleaner approach could be leaving that constructor and field available for all configurations, but saving the string only in debug, something like this:<br />
Symbol::Symbol(u32 sym, char * str)<br />
{<br />
  _sym = sym;<br />
#if _DEBUG<br />
  _str = str;<br />
#else<br />
  _str = 0;<br />
#endif<br />
}</p>
<p>const char * Symbol::getStr()<br />
{<br />
   if (!_str) return &#8220;&#8221;;<br />
   return _str;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gus</title>
		<link>http://entland.homelinux.com/blog/2009/04/28/compile-time-strings/comment-page-1/#comment-168566</link>
		<dc:creator>Gus</dc:creator>
		<pubDate>Sat, 02 May 2009 11:28:36 +0000</pubDate>
		<guid isPermaLink="false">http://entland.homelinux.com/blog/?p=346#comment-168566</guid>
		<description>Do you have a way to know the associated string to a Symbol(number), for instance, when you are debugging?</description>
		<content:encoded><![CDATA[<p>Do you have a way to know the associated string to a Symbol(number), for instance, when you are debugging?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: hcpizzi</title>
		<link>http://entland.homelinux.com/blog/2009/04/28/compile-time-strings/comment-page-1/#comment-168550</link>
		<dc:creator>hcpizzi</dc:creator>
		<pubDate>Wed, 29 Apr 2009 11:16:02 +0000</pubDate>
		<guid isPermaLink="false">http://entland.homelinux.com/blog/?p=346#comment-168550</guid>
		<description>Why didn&#039;t you choose to do something like this?

typedef size_t Symbol;

#define DECLARE_SYMBOL(id)\
    static Symbol SYMBOL_##id = GetIdFromString(#id);

#define S(id) SYMBOL_##id

That way you don&#039;t have to worry about making GetIdFromString thread-safe because it will only be called from the C runtime static initializer, which is guaranteed to be single threaded, and all the cost associated with it will be removed from the runtime. Is there any downside to this approach?</description>
		<content:encoded><![CDATA[<p>Why didn&#8217;t you choose to do something like this?</p>
<p>typedef size_t Symbol;</p>
<p>#define DECLARE_SYMBOL(id)\<br />
    static Symbol SYMBOL_##id = GetIdFromString(#id);</p>
<p>#define S(id) SYMBOL_##id</p>
<p>That way you don&#8217;t have to worry about making GetIdFromString thread-safe because it will only be called from the C runtime static initializer, which is guaranteed to be single threaded, and all the cost associated with it will be removed from the runtime. Is there any downside to this approach?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
