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
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
Fantastic video.
__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.
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.
Suggestion: Do an episode like this for every standard C++ command and put them into a playlist for new programmers.
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.
THANK YOU GOOD SIR! YOU ARE GENIUS! Please keep up the good work!
If that channel dropped all the nerdy stuff, I'd still show up for the great metaphors!
Thanks-- good vid again. Never occurred food for thought!
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!
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.
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.
I knew it was a complex function, but this is news.
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!
Thanks Dave👍!
"Elegance is when the code knows exactly what it's doing, uses exactly what it needs, and leaves nothing unnecessary behind."
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.
"[...] '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 printf course in 17 minutes. Love it.
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.
Dave refused to use monospaced fonts on those code snippets just to troll us I swear. 😂