<?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"
	>
<channel>
	<title>Comments on: Where the printf() Rubber Meets the Road</title>
	<atom:link href="http://www.hostilefork.com/2010/03/14/where-the-printf-rubber-meets-the-road/feed/" rel="self" type="application/rss+xml" />
	<link>http://hostilefork.com/2010/03/14/where-the-printf-rubber-meets-the-road/</link>
	<description>a disgruntled developer taking a stand in the information multiverse</description>
	<pubDate>Sat, 04 Feb 2012 09:31:59 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5</generator>
		<item>
		<title>By: thavali</title>
		<link>http://hostilefork.com/2010/03/14/where-the-printf-rubber-meets-the-road/#comment-1244</link>
		<dc:creator>thavali</dc:creator>
		<pubDate>Mon, 24 Jan 2011 15:48:50 +0000</pubDate>
		<guid isPermaLink="false">http://hostilefork.com/?p=135#comment-1244</guid>
		<description>dear all,
So, Printf function will find out the low-level function base on FILE object information (stdout) or get low-level function by it's self ?
low-level function which can put a character to FILE object.

please refer: http://cboard.cprogramming.com/c-programming/134041-file-object-c-cplusplus.html#post997853</description>
		<content:encoded><![CDATA[<p>dear all,<br />
So, Printf function will find out the low-level function base on FILE object information (stdout) or get low-level function by it&#8217;s self ?<br />
low-level function which can put a character to FILE object.</p>
<p>please refer: <a href="http://cboard.cprogramming.com/c-programming/134041-file-object-c-cplusplus.html#post997853" rel="nofollow" target="_blank" class="liexternal">http://cboard.cprogramming.com/c-programming/134041-file-object-c-cplusplus.html#post997853</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nuclear</title>
		<link>http://hostilefork.com/2010/03/14/where-the-printf-rubber-meets-the-road/#comment-1109</link>
		<dc:creator>Nuclear</dc:creator>
		<pubDate>Sat, 15 May 2010 18:56:58 +0000</pubDate>
		<guid isPermaLink="false">http://hostilefork.com/?p=135#comment-1109</guid>
		<description>The question, although ineptly phrased was whether it's possible to implement printf completely with C or if there's any bit of code needed: "Something like in dos, first mov beginning of the string to some memory location or register and than call some int"

The implied answer from your post is "you can do the whole thing in C"

The real answer is "you must trap the processor to enter the supervisor code which is done using a little bit of assembly" In fact the bit of assembly code you must write under x86 linux in order to output a string is strikingly similar to the piece of code the original poster described.

You put the syscall number (4) in eax, then you put the file descriptor in ebx, the pointer to the buffer in ecx, and the number of bytes to write in edx, and then raise the software interrupt 80h.

And no LDM, that's not in the kernel, we're talking user space now, and the implementation of syscall in libc in particular.

There are other methods to call syscalls now like sysenter, they all still require a little bit of assembly code somewhere in the depths of libc.</description>
		<content:encoded><![CDATA[<p>The question, although ineptly phrased was whether it&#8217;s possible to implement printf completely with C or if there&#8217;s any bit of code needed: &#8220;Something like in dos, first mov beginning of the string to some memory location or register and than call some int&#8221;</p>
<p>The implied answer from your post is &#8220;you can do the whole thing in C&#8221;</p>
<p>The real answer is &#8220;you must trap the processor to enter the supervisor code which is done using a little bit of assembly&#8221; In fact the bit of assembly code you must write under x86 linux in order to output a string is strikingly similar to the piece of code the original poster described.</p>
<p>You put the syscall number (4) in eax, then you put the file descriptor in ebx, the pointer to the buffer in ecx, and the number of bytes to write in edx, and then raise the software interrupt 80h.</p>
<p>And no LDM, that&#8217;s not in the kernel, we&#8217;re talking user space now, and the implementation of syscall in libc in particular.</p>
<p>There are other methods to call syscalls now like sysenter, they all still require a little bit of assembly code somewhere in the depths of libc.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jay</title>
		<link>http://hostilefork.com/2010/03/14/where-the-printf-rubber-meets-the-road/#comment-1107</link>
		<dc:creator>Jay</dc:creator>
		<pubDate>Sat, 15 May 2010 09:17:14 +0000</pubDate>
		<guid isPermaLink="false">http://hostilefork.com/?p=135#comment-1107</guid>
		<description>Matt: where in the question do you see 'in the standard library'?  Yes, it is needlessly complicated by choosing one of the most rococo libc implementations around, a BSD libc or uclibc might be more enlightening, rather than serving to demonstrate the author's ability to understand the horrible GNU libc code.</description>
		<content:encoded><![CDATA[<p>Matt: where in the question do you see &#8216;in the standard library&#8217;?  Yes, it is needlessly complicated by choosing one of the most rococo libc implementations around, a BSD libc or uclibc might be more enlightening, rather than serving to demonstrate the author&#8217;s ability to understand the horrible GNU libc code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://hostilefork.com/2010/03/14/where-the-printf-rubber-meets-the-road/#comment-1105</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Fri, 14 May 2010 18:15:04 +0000</pubDate>
		<guid isPermaLink="false">http://hostilefork.com/?p=135#comment-1105</guid>
		<description>@Nuclear, the question was specifically how it's implemented in C/C++ in the standard library.  It's hardly "misleading" when this is the exact answer traced through the real code base.  It might be a "needlessly complicated" implementation, but it's still the answer when using GNU's libc.</description>
		<content:encoded><![CDATA[<p>@Nuclear, the question was specifically how it&#8217;s implemented in C/C++ in the standard library.  It&#8217;s hardly &#8220;misleading&#8221; when this is the exact answer traced through the real code base.  It might be a &#8220;needlessly complicated&#8221; implementation, but it&#8217;s still the answer when using GNU&#8217;s libc.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: eeeeee</title>
		<link>http://hostilefork.com/2010/03/14/where-the-printf-rubber-meets-the-road/#comment-1103</link>
		<dc:creator>eeeeee</dc:creator>
		<pubDate>Fri, 14 May 2010 16:55:54 +0000</pubDate>
		<guid isPermaLink="false">http://hostilefork.com/?p=135#comment-1103</guid>
		<description>http://www.digipedia.pl/man/doc/view/varargs.3/

everybody can have variable argument lists.

where is the news?</description>
		<content:encoded><![CDATA[<p><a href="http://www.digipedia.pl/man/doc/view/varargs.3/" rel="nofollow" target="_blank" class="liexternal">http://www.digipedia.pl/man/doc/view/varargs.3/</a></p>
<p>everybody can have variable argument lists.</p>
<p>where is the news?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marius Gedminas</title>
		<link>http://hostilefork.com/2010/03/14/where-the-printf-rubber-meets-the-road/#comment-1102</link>
		<dc:creator>Marius Gedminas</dc:creator>
		<pubDate>Fri, 14 May 2010 15:56:15 +0000</pubDate>
		<guid isPermaLink="false">http://hostilefork.com/?p=135#comment-1102</guid>
		<description>I love articles that dig through multiple stacks to explain how something works!</description>
		<content:encoded><![CDATA[<p>I love articles that dig through multiple stacks to explain how something works!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: LDM</title>
		<link>http://hostilefork.com/2010/03/14/where-the-printf-rubber-meets-the-road/#comment-1101</link>
		<dc:creator>LDM</dc:creator>
		<pubDate>Fri, 14 May 2010 14:55:08 +0000</pubDate>
		<guid isPermaLink="false">http://hostilefork.com/?p=135#comment-1101</guid>
		<description>Ahh, Nuclear...

If only it was that simple.  Your computer doesn't run assembly: Assembly gets translated to Machine code.  Some C compilers (very rare though) may even skip over assembly and go straight to machine code.

The thing is, most modern processors don't even run machine code:  it is translated into processor microcode, which (usually) actually executes on the processor.  Granted, the microcode translation is usually done ON the processor itself.

So the answer really depends on what level of the system you're looking at, and how far down the rabbit hole you want to go.  He stopped at the C libraries: printf is not inline assembly in the C libraries: the assembly is in the Kernel (at least under linux).   As a library implementer, you don't have to know assembly to program printf().  You go one step further, and say that to implement the functionality at the kernel level, you need to know assembly.  I'm going one step further and saying in order to get your assembly to run on the processor you have to know machine code, and to implement the assembly on the processor you have to understand microcode.

In the end, it gets converted into electrons running around little electrical paths... you could say in the end to implement printf() you have to know physics ;-)</description>
		<content:encoded><![CDATA[<p>Ahh, Nuclear&#8230;</p>
<p>If only it was that simple.  Your computer doesn&#8217;t run assembly: Assembly gets translated to Machine code.  Some C compilers (very rare though) may even skip over assembly and go straight to machine code.</p>
<p>The thing is, most modern processors don&#8217;t even run machine code:  it is translated into processor microcode, which (usually) actually executes on the processor.  Granted, the microcode translation is usually done ON the processor itself.</p>
<p>So the answer really depends on what level of the system you&#8217;re looking at, and how far down the rabbit hole you want to go.  He stopped at the C libraries: printf is not inline assembly in the C libraries: the assembly is in the Kernel (at least under linux).   As a library implementer, you don&#8217;t have to know assembly to program printf().  You go one step further, and say that to implement the functionality at the kernel level, you need to know assembly.  I&#8217;m going one step further and saying in order to get your assembly to run on the processor you have to know machine code, and to implement the assembly on the processor you have to understand microcode.</p>
<p>In the end, it gets converted into electrons running around little electrical paths&#8230; you could say in the end to implement printf() you have to know physics <img src='http://hostilefork.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Uwe</title>
		<link>http://hostilefork.com/2010/03/14/where-the-printf-rubber-meets-the-road/#comment-1100</link>
		<dc:creator>Uwe</dc:creator>
		<pubDate>Fri, 14 May 2010 13:52:15 +0000</pubDate>
		<guid isPermaLink="false">http://hostilefork.com/?p=135#comment-1100</guid>
		<description>I really did like assembler programming back in the mid-1990s...</description>
		<content:encoded><![CDATA[<p>I really did like assembler programming back in the mid-1990s&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Breakable</title>
		<link>http://hostilefork.com/2010/03/14/where-the-printf-rubber-meets-the-road/#comment-1099</link>
		<dc:creator>Breakable</dc:creator>
		<pubDate>Fri, 14 May 2010 13:30:32 +0000</pubDate>
		<guid isPermaLink="false">http://hostilefork.com/?p=135#comment-1099</guid>
		<description>This is crazy. I am sticking with managed development to stay out of this hell you call system programming...</description>
		<content:encoded><![CDATA[<p>This is crazy. I am sticking with managed development to stay out of this hell you call system programming&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: spotter</title>
		<link>http://hostilefork.com/2010/03/14/where-the-printf-rubber-meets-the-road/#comment-1098</link>
		<dc:creator>spotter</dc:creator>
		<pubDate>Fri, 14 May 2010 13:24:20 +0000</pubDate>
		<guid isPermaLink="false">http://hostilefork.com/?p=135#comment-1098</guid>
		<description>uclibc is a better version to see, glbic is insanely complicated.  the uclibc version is somewhat crazy as well, but that's because printf is a fairly complicated function with all the conversions built into it, but is basically contained in a single file.

you can see this in other places with how glibc does crazy stuff when doing simple things such as wrapping system calls.</description>
		<content:encoded><![CDATA[<p>uclibc is a better version to see, glbic is insanely complicated.  the uclibc version is somewhat crazy as well, but that&#8217;s because printf is a fairly complicated function with all the conversions built into it, but is basically contained in a single file.</p>
<p>you can see this in other places with how glibc does crazy stuff when doing simple things such as wrapping system calls.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

