0:00
16:54
16:54

printf is Actually a Secret Virtual Machine - And a Giant Security Hole!

Tech

Dave explains printf and how to take advantage of its most powerful features. Check out an episode of ShopTalk on Dave's Attic where we answer the best user questions! https://youtu.be/ZUvDO2g5Y1s

ADVERTISEMENT

Comments 100

Sign in to join the conversation

Sign in
B
bradley.page 4 weeks, 2 days ago

Fantastic video.

S
suzannelloyd476 4 weeks, 2 days ago

__attribute(printf, ...)__ is very useful in GNU C as it lets you tell the compiler that the function accepts a printf-style format string. (Similar versions exist for scanf). This enables format checking on functions that are printf-like that take format strings. One project I did was enable it on a project we had, and the build failed with like 200 errors. Eventually we cleaned up the strings and formats so it built cleanly, so that was getting rid of 200 potential crashes. Nevermind how I wasted half a day debugging something only to find out it was my debugging printf that was the root cause of the new crash.

J
julianafliegner841 4 weeks, 2 days ago

A finite state machine can be written as a determination automata. Which will read one input per stage change, which in turn means constant time. And a complexity of regular.

G
garytaylor19 4 weeks, 2 days ago

Suggestion: Do an episode like this for every standard C++ command and put them into a playlist for new programmers.

angela.patterson
angela.patterson 4 weeks, 2 days ago

Lots of embedded ports of compilers have supported %b for binary for a large number of years. And that has probably been the reason why it took so long until standardized - most people needing it has already had access to binary print.

D
danielleadams340 4 weeks, 2 days ago

THANK YOU GOOD SIR! YOU ARE GENIUS! Please keep up the good work!

J
johnaura45 4 weeks, 2 days ago

If that channel dropped all the nerdy stuff, I'd still show up for the great metaphors!

keith_davis
keith_davis 1 month ago

Thanks-- good vid again. Never occurred food for thought!

A
anastasiegermain638 1 month ago

Fabulous! I've been writing C on and off for something like 40 years and I had never tripped over a couple of those, and I had no idea the standards comittee finally added %b!

M
meganmccarthy268 1 month ago

Much more efficient & scalable than the many algebraic notations & universes of toString functions that replaced it. Lions typecast all the arguments to int & float to avoid the ever changing percent codes.

L
lorraine_powell 1 month ago

Love your content man, you shifted my naive negative perspective of MS to a more respective appreciation for programmers like yourself that have built it. P.S. Valuable info on printf,had massive memory leaks in my first larger project because of careless use of it.

C
christopher_moon 1 month ago

I knew it was a complex function, but this is news.

R
robertyadav686 1 month ago

It's been over 20 years since I last used printf in C, and I dare say my uni assignments would have been a lot prettier if I knew how to use printf to the fullest! Top tier content Dave!

M
maria_evans 1 month ago

Thanks Dave👍!

C
crystal.johnson 1 month ago

"Elegance is when the code knows exactly what it's doing, uses exactly what it needs, and leaves nothing unnecessary behind."

H
hans-hinrichhendriks264 1 month ago

Grew up a C programmer using printf() extensively. I learned and used all of the features on a regular basis. Always loved it. I was very anal about how output was formatted. I sought perfection and could get it with printf(). Thank you Dave for showing the code behind the scenes. I've also done a lot of state machine programming. It's one of my favorite approaches having done so much automation triggered by events and modes external to the code. Not only do we need to remember to tighten the lugs nuts on our Camaro, we need to use a torque wrench to do it.

A
andrew_martin 1 month ago

"[...] 'repne scasb', one of those lovely old x86 string instructions that feels like it came from a CPU designed by somebody who wanted assembly language programmers to have a fighting chance" had me dying of laughter so hard I had to pause the video. I absolutely love your dry sense of humor, thank you for yet another video that is simultaneously deeply enlightening and thoroughly entertaining!

A
angela_rodriguez 1 month ago

A printf course in 17 minutes. Love it.

howardandrews312
howardandrews312 1 month ago

Great episode Dave. Agreed on "what took so long to add %b". I like using snprintf's return value to become a more efficient strcat.

N
nermin.täsche 1 month ago

Dave refused to use monospaced fonts on those code snippets just to troll us I swear. 😂