ChatGPT-driven development
zverovich
by Victor Zverovich
4M ago
ChatGPT-driven development In the vast, often inexplicable universe of C++ programming, I found myself staring into the digital abyss of a peculiar problem: how does one effectively compare format_as with the venerable formatter specialization? This question was as intriguing as it was esoteric, much like pondering the number of Vogon ships in the Galactic Fleet. But fear not, for my quest was not solitary. I had a companion, an AI of improbable intelligence and wit: ChatGPT. (As you might have guessed I got some help from ChatGPT in writing a catchy introductory paragraph as well.) First, so ..read more
Visit website
Printing double aka the most difficult problem in computer sciences
zverovich
by Victor Zverovich
11M ago
Printing double aka the most difficult problem in computer sciences A few years ago I discovered this StackOverflow question: How do I print a double value with full precision using cout? I was shocked to see how wrong most of the answers were so I answered it myself back then. Recently I stumbled upon it again and decided to write this blog post explaining the problems with some of the top answers. Consider the accepted answer with almost 500 upvotes. The first part of it gives us this method: double d = 3.14159265358979; cout.precision(17); cout << "Pi: " << fixed << d ..read more
Visit website
Simple usage of C++20 modules
zverovich
by Victor Zverovich
1y ago
Simple usage of C++20 modules In my previous post I showed how to compile {fmt} as a C++20 module with clang. Although taking only two commands, ideally it’s not something you should be doing manually. So in this post, I’ll talk about module support in CMake, everyone’s favorite not a build system. My first attempt was to use the CMake’s built-in functionality advertised in “import CMake; C++20 Modules”. And after some struggle I made it to work with clang but unfortunately it was very limited. Here are some of the problems and limitations that I discovered: It only worked with ninja and wh ..read more
Visit website
C++20 modules in clang
zverovich
by Victor Zverovich
1y ago
C++20 modules in clang Out of three headline C++20 features (modules, coroutines and the third one), modules are, in my opinion, by far the most important for the daily use. Modules aim to replace the legacy header system inherited from C and based on primitive textual inclusion with a more scalable, hermetic and fine-grained system. There has been slow but steady progress on implementing modules in various compilers and build systems. I recently read a blog post “import CMake; C++20 Modules” and, among other things, learned that Clang 16 supports modules out of the box. So I decided to give ..read more
Visit website
IOS SSID format string bug is preventable
zverovich
by Victor Zverovich
2y ago
iOS SSID format string bug is preventable After joining my personal WiFi with the SSID “%p%s%s%s%s%n”, my iPhone permanently disabled it’s WiFi functionality. Neither rebooting nor changing SSID fixes it :~) — Carl Schou (@vm_call) June 18, 2021 The SSID format string bug in iOS WiFi service has been making rounds on social media. This blog post nicely pinpoints the root cause to concatenating the SSID with a string and passing the result to a logging method that uses it as a format string. Let’s see how modern APIs like the ones of the {fmt} formatting library and C++20 std::format can pre ..read more
Visit website
A quest for safe text formatting API
zverovich
by Victor Zverovich
2y ago
A quest for safe text formatting API Since the introduction of format strings in Fortran in the 50s pretty much all major programming languages used them in their text formatting and I/O APIs: printf-based: C, Haskell, Java/JVM languages, PHP and others Python-format-based: Python, Rust, C++ (starting from C++20) NIH-based: C#/.NET One notable exception is C++ iostreams that use operator overloading and per-stream state manipulation to control formatting. At this point stateful APIs have pretty much proved to be a failure in terms of usability and performance and many C++ programmers prefer ..read more
Visit website
Writing files 5 to 9 times faster than fprintf
zverovich
by Victor Zverovich
2y ago
Writing files 5 to 9 times faster than fprintf "The value of BUFSIZ has been chosen at random in 1989 and can no longer be changed because that would break ABI." — Peter Dimov (@pdimov2) August 1, 2020 I recently added a new unsynchronized file output API to the {fmt} library. Together with format string compilation, zero memory allocations and locale-independent formatting by default this gives you a high performance file output from a single thread. Here’s a small example demonstrating the new API: #include <fmt/os.h> int main() { auto f = fmt::output_file("guide"); f.print ..read more
Visit website
Converting a hundred million integers to strings per second
zverovich
by Victor Zverovich
2y ago
Converting a hundred million integers to strings per second Almost 7 years ago I wrote a blog post comparing performance of different methods of converting an integer into a string. A lot of things have changed since then so I decided to write a follow-up post and see how much progress has been made over the years. First of all let’s look at the benchmark itself. It is based on Boost Karma int_performance benchmark ported to Google Benchmark to make the results more reproducible. It reports the time taken to convert ten million integers into strings. This is a somewhat weird metric so I chang ..read more
Visit website
Reducing {fmt} library size 4x using Bloaty McBloatface
zverovich
by Victor Zverovich
2y ago
Reducing {fmt} library size 4x using Bloaty McBloatface When it comes to comparing different software solutions, speed is often the main if not the only factor considered. This is not the case in the {fmt} library which tries to find a good balance between speed, binary size and compile times by default and give you an option to get maximum performance in cases that matter. A lot of effort has been put into making binary code at the usage site very compact, comparable to that of printf. For example (godbolt): #include <fmt/core.h> int main() { fmt::print("The answer is {}.\n", 42 ..read more
Visit website
Std::format in C++20
zverovich
by Victor Zverovich
2y ago
std::format in C++20 I’m happy to announce that the Text Formatting proposal (std::format) made it into the C++20 Committee Draft at the Cologne meeting, just in time before the feature freeze. This concludes a three-year long design, implementation, and standardization effort. Here’s a brief history of the proposal aka “what took you so long?”: 2016-08-17: posted on Reddit floating the proposal idea 2016-08-27: committed the initial proposal draft on GitHub 2017-07-10 to 15, Toronto, Canada: presented revision 0 (R0 - as all sensible people we use zero-based revision numbers) of the pro ..read more
Visit website

Follow zverovich on FeedSpot

Continue with Google
Continue with Apple
OR