Has anyone ever had the need or experienced the use of the %n formatting code in a printf statement in C/C++?
I've read a lot of code, but I've never seen production code that uses this. And I'm kind of surprised such a beast exists.
Instead of printing the variable to which it refers, it writes to the variable a value representing the number of characters the statement has printed up to that point.
I suppose it was created to help deal with formatting concerns in elaborate lines of text, but... wow... that's obscure.
Working with managed code (whether Java or C#) puts me in mind of
Apple creating a programming language or something.
Yup. Today's programmers are isolated from the machine. It's too bad.
Probably the best applications today are the ones where the core logic is written in a Real Language and then has extensions written in "managed code"
The %n thing...
Turns out, at least in Windows, you have to call some other function to enable it, or it won't work.
But it's considered 'exploitable', since you can use it to write memory anywhere if you're sorta evil and know that someone ignorantly exposed printf by allowing a human to drop in whatever formatting field they want.
Nifty-weird.
Probably the best applications today are the ones where the core logic
is written in a Real Language and then has extensions written in
"managed code"
I agree.
You get the advantages of the managed code by letting it take care of the crap that's kinda difficult to handle, while getting the advantages of working closer to the wire by having that meticulous attention to how memory is being used, etc.
hm, this sounds like something we may put into libcitadel too...
http://blog.kazuhooku.com/2014/12/improving-parser-performance-using-sse.html
(found on ycombinator ;-)
dothebart,
You are evil smart :-) Glad you are creative and not malicious! Of course, that is just an assumption you don't have a side job - JK
But I like what I see here:
https://github.com/h2o/picohttpparser/blob/master/picohttpparser.c
Around like 139, DOIT(); DOIT(); DOIT(); and so on.
Even the 'if (unlikely(' bit kinda gives me a chuckle.
Oh, yeah, has anyone here heard of Duff's device?
You can use it to portably create coroutines in C, but... it's... not very nice:
http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
Even the 'if (unlikely(' bit kinda gives me a chuckle.
I saw that. Must be an annotation for the branch-predictor. Didn't know you could do that, even in C. I am getting old.
Either that, or you could say "Java has completely ruined LoanShark for any Real Programming"... take your pick.
I'm lucky (or unfortunate) that I can still work with C++. But I'm finding myself doing more Java and C# stuff as time passes.
I've been a c-guy for the recent years...
doing some python for the scripting the last year, now js replaces that due to the job...
Wed Dec 03 2014 10:49:51 AM EST from fleeb @ Uncensored
But I like what I see here:
https://github.com/h2o/picohttpparser/blob/master/picohttpparser.c
Around like 139, DOIT(); DOIT(); DOIT(); and so on.
Even the 'if (unlikely(' bit kinda gives me a chuckle.
Noooooooooooooooooooooooooooooooooooooooooooooooooooooooooo.