News for hackers. Stuff that matters.
Re:Where the Printf Rubber Meets the Road (2010) by asveikau on Saturday October 04, 2014 @05:50PM (#8410778)
I think the question comes from a lack of understanding of varargs, not a desire to see a bunch of crappy glue code inside glibc.

And for that type of C newbie who hasn't seen varargs... I'd say the answer is pretty intuitive if you know how to look. First of all the answer is staring at you in the manpage:

   int printf(const char *s, ...);
   int vprintf(const char *s, va_list ap);
OK, so there is the set of ordinary C functions that do it. Look up this va_list thing and an implementation becomes obvious... printf sets up a va_list and calls vprintf... vprintf scans the string for '%' and uses va_arg...

But the important thing is none of this is magic and you can totally guess it just by looking at documentation. I don't think it ever confused me when I learned C. I don't really get why this is so shocking to people who read the manpages.

Re:Where the Printf Rubber Meets the Road (2010) by zem on Saturday October 04, 2014 @06:01PM (#8410796)
what? the question had nothing to do with varargs; the poster quite rightly noted that at some point in the implementation of printf, when you needed to send an actual character to an actual output device, you would need something conceptually lower-level than C. they were just confused about the specifics of interfacing between C and the machine; i think one of the comment-level answers put its finger on the nub:

> Visual Studio x64 doesn't support inline assembler. That doesn't mean you can't have assembler code. You can still have assembler, just not inline.

and in the answer section

> The system calls are (on platforms that I know of) internally implemented by a call to a function with inline asm that puts a system call number and parameters in CPU registers and triggers an interrupt that the kernel then processes.

Re:Where the Printf Rubber Meets the Road (2010) by asveikau on Saturday October 04, 2014 @06:41PM (#8410883)
I have a hard time seeing this as a magical part even in the eyes of a newbie. How common is it to hear about stdio but not also know about write()? I am pretty sure one man page refers to another. My point, just as it is with varargs, is you should be curious enough to find these answers yourself, run some experiments, make some good guesses.

Since Visual Studio is mentioned, I'll say that despite some extra layers (CRT, kernel32, ntdll) the concepts are identical and when I was a kid learning C I was able to dig through header files and documentation to conceptually figure it out.

Re:Where the Printf Rubber Meets the Road (2010) by zem on Saturday October 04, 2014 @07:00PM (#8410922)
it's not a question of anything being magical; the op just got confused by the difference between writing inline assembly in a c program and calling from c code into compiled and linked in assembly code.
Re:Where the Printf Rubber Meets the Road (2010) by asveikau on Saturday October 04, 2014 @09:21PM (#8411140)
I'll say, somebody is a little confused.

I still say, they don't understand varargs, don't understand the difference between stdio and write(), and most importantly, they are not curious enough to read documentation and make smart guesses. And I am saying, the bullshit obfuscation involved in this article, sharing so many meaningless implementation details about a very specific libc, will not help answer this question or gain insight more than RTFMing and being curious about the world would.

So... If you are even asking questions like... "Does printf use assembly?" I'd argue you are not thinking it through. You need to get yourself to a place where you can answer that yourself. It will be a very obvious answer when you do. Writing frivolous blog posts is not the way to get there.

Re:Where the Printf Rubber Meets the Road (2010) by hostilefork on Saturday October 04, 2014 @09:24PM (#8411148)
Just noting that the article is not the source of the bullshit obfuscation, nor does it condone it. I'm part of the Red project.

http://www.red-lang.org/p/contributions.html

We're trying to undo this stuff. I was just answering a question.

Re:Where the Printf Rubber Meets the Road (2010) by asveikau on Sunday October 05, 2014 @02:24PM (#8412963)
The article struck me as such because the important point is not how glibc layers things, it's the conceptual detail that stdio buffers first and then flushes with write(). [You happened to pick a really bad libc to pick apart because a much simpler implementation is possible.] If someone saw your post having no idea they would have to parse it out of what you are saying, and probably get lost, because you did not say it plainly.
Re:Where the Printf Rubber Meets the Road (2010) by zem on Saturday October 04, 2014 @09:33PM (#8411171)
red looks awesome, and has come a lot further than I expected! (i peeked at it a few years ago and there didn't seem to be much). I love that small executable sizes are an explicit design goal.
Re:Where the Printf Rubber Meets the Road (2010) by hostilefork on Sunday October 05, 2014 @09:29AM (#8412227)
The next release will be able to directly build and sign .APK files, with no JDK or JarSigner required to be installed. Still under 1MB for that same compiler executable on all platforms...that can also build PE (Windows), Mach-O (OS/X), and ELF (Linux etc.)

It's moving slower than we'd like, but definitely moving.