Add snprintf fallback for float/double formatting (IAR support)#2
Merged
Conversation
…ut floating std::to_chars
Integer std::to_chars is universally available, but the floating-point
overloads are not implemented everywhere: IAR's libc++ (bxarm) ships
std::to_chars(float/double) as deleted functions, so StringBuilder.cpp
fails to compile there even when no float/double is ever formatted.
Guard the four floating-point formatters (append/prepend for float and
double) behind NFX_STRINGBUILDER_HAS_FLOAT_TO_CHARS, which defaults to 0
under IAR and 1 elsewhere, and can be overridden by the consumer. When
disabled, format via std::snprintf("%.*g", max_digits10, ...) into a
stack buffer and reuse the existing append/prepend(string_view) path.
Integer formatting is untouched.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
nehalkpatel
reviewed
Jul 7, 2026
nehalkpatel
approved these changes
Jul 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Guards the four floating-point
StringBuilderformatters (append/prependforfloatanddouble) behind a newNFX_STRINGBUILDER_HAS_FLOAT_TO_CHARSmacro. When floatingstd::to_charsis unavailable, they fall back tostd::snprintf("%.*g", max_digits10, ...)into a stack buffer and reuse the existingappend/prepend(std::string_view)path. Integer formatting is unchanged.The macro defaults to
0under IAR (__IAR_SYSTEMS_ICC__) and1elsewhere, and can be overridden by the consumer before including the header.Motivation and Context
Integer
std::to_charsis universally available, but the floating-point overloads are not: IAR's libc++ (bxarm) shipsstd::to_chars(float/double)as deleted functions. BecauseStringBuilder.cppinstantiates everyappend/prependoverload, the library currently fails to cross-compile under IAR even when the consumer never formats a float or double.This came up integrating nfx-stringbuilder into an embedded (arm-cm7-iar) firmware build for MQTT topic construction, which only ever appends integers and string literals.
How Has This Been Tested?
StringBuilder.cpp) with IAR bxarm 9.50.2 for arm-cm7 — fails without this change (deletedstd::to_chars), links cleanly with it.std::to_charspath.🤖 Generated with Claude Code