printf | fully loaded printf implementation for embedded systems

 by   mpaland C Version: v4.0.0 License: MIT

kandi X-RAY | printf Summary

kandi X-RAY | printf Summary

printf is a C library typically used in Embedded System applications. printf has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. You can download it from GitHub.

This is a tiny but fully loaded printf, sprintf and (v)snprintf implementation. Primarily designed for usage in embedded systems, where printf is not available due to memory issues or in avoidance of linking against libc. Using the standard libc printf may pull a lot of unwanted library stuff and can bloat code size about 20k or is not 100% thread safe. In this cases the following implementation can be used. Absolutely NO dependencies are required, printf.c brings all necessary routines, even its own fast ftoa (floating point), ntoa (decimal) conversion. If memory footprint is really a critical issue, floating point, exponential and 'long long' support and can be turned off via the PRINTF_DISABLE_SUPPORT_FLOAT, PRINTF_DISABLE_SUPPORT_EXPONENTIAL and PRINTF_DISABLE_SUPPORT_LONG_LONG compiler switches. When using printf (instead of sprintf/snprintf) you have to provide your own _putchar() low level function as console/serial output.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              printf has a medium active ecosystem.
              It has 2086 star(s) with 403 fork(s). There are 67 watchers for this library.
              OutlinedDot
              It had no major release in the last 12 months.
              There are 50 open issues and 49 have been closed. On average issues are closed in 20 days. There are 17 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of printf is v4.0.0

            kandi-Quality Quality

              printf has 0 bugs and 0 code smells.

            kandi-Security Security

              printf has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              printf code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              printf is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              printf releases are available to install and integrate.
              Installation instructions are not available. Examples and code snippets are available.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of printf
            Get all kandi verified functions for this library.

            printf Key Features

            No Key Features are available at this moment for printf.

            printf Examples and Code Snippets

            No Code Snippets are available at this moment for printf.

            Community Discussions

            QUESTION

            Using NativeCall to call the C fn `erf` gets more precise output than `erf` in C
            Asked 2022-Mar-06 at 09:09

            I have written a Raku script to call erf function in C standard library:

            ...

            ANSWER

            Answered 2022-Feb-04 at 12:56

            For the C code, change %f to %.99g to show more digits. This reveals erf(4) returns 0.9999999845827420852373279558378271758556365966796875.

            %f requests six digits after the decimal point. The value is rounded to fit that format. %.numberf requests number digits after the decimal point and always used the “fixed” format. %.numberg requests number significant digits and uses a a “general” format that switches to exponential notation when appropriate.

            For the Raku code, if you want output of “1.0” or “1.000000”, you will need to apply some formatting request to the output. I do not practice Raku, but a brief search shows Raku has printf-like features you can use, so requesting the %f format with it should duplicate the C output.

            Source https://stackoverflow.com/questions/70986616

            QUESTION

            Docker standard_init_linux.go:228: exec user process caused: no such file or directory
            Asked 2022-Feb-08 at 20:49

            Whenever I am trying to run the docker images, it is exiting in immediately.

            ...

            ANSWER

            Answered 2021-Aug-22 at 15:41

            Since you're already using Docker, I'd suggest using a multi-stage build. Using a standard docker image like golang one can build an executable asset which is guaranteed to work with other docker linux images:

            Source https://stackoverflow.com/questions/68881023

            QUESTION

            How can I print the offset of a struct member at compile time?
            Asked 2022-Jan-28 at 18:48

            Given a struct, for instance:

            ...

            ANSWER

            Answered 2021-Sep-16 at 15:30

            QUESTION

            What does this mean: a pointer to void will never be equal to another pointer?
            Asked 2021-Aug-03 at 19:51

            One of my friends pointed out from "Understanding and Using C Pointers - Richard Reese, O'Reilly publications" the second bullet point and I wasn't able to explain the first sentence from it. What am I missing?

            Pointer to void

            A pointer to void is a general-purpose pointer used to hold references to any data type. An example of a pointer to void is shown below:

            ...

            ANSWER

            Answered 2021-Aug-01 at 13:45

            The following section from this Draft C11 Standard completely refutes the claim made (even with the clarification mentioned in the 'errata', in the comment by GSerg).

            6.3.2.3 Pointers

            1     A pointer to void may be converted to or from a pointer to any object type. A pointer to any object type may be converted to a pointer to void and back again; the result shall compare equal to the original pointer.

            Or, this section from the same draft Standard:

            7.20.1.4 Integer types capable of holding object pointers

            1    The following type designates a signed integer type with the property that any valid pointer to void can be converted to this type, then converted back to pointer to void, and the result will compare equal to the original pointer:

                  intptr_t

            Source https://stackoverflow.com/questions/68610799

            QUESTION

            Are symbols from the C standard library reserved in C++?
            Asked 2021-Jul-21 at 02:54

            This is a followup to a different question.

            The original question had other problems but I had to realize that the main one (according to CLang) was a redefinition of time as a different symbol while only nice C++ includes were used.

            So here is a stripped down version:

            ...

            ANSWER

            Answered 2021-Jul-20 at 12:46

            Where does the C++ standard forbids to use freely symbols from the C standard library

            Latest draft:

            [extern.names]

            Each name from the C standard library declared with external linkage is reserved to the implementation for use as a name with extern "C" linkage, both in namespace std and in the global namespace.

            Each function signature from the C standard library declared with external linkage is reserved to the implementation for use as a function signature with both extern "C" and extern "C++" linkage, or as a name of namespace scope in the global namespace.

            when they are not explicitely included in a compilation unit?

            If you use the standard library at all, then all name reservations of the standard library are in effect.

            If you include any standard header (or, any header whose exact content you don't control and thus may include standard headers), then you may be indirectly including other standard headers, including those inherited from C.

            Source https://stackoverflow.com/questions/68455008

            QUESTION

            Efficient modulo-255 computation
            Asked 2021-Jun-24 at 07:23

            I am trying to find the most efficient way to compute modulo 255 of an 32-bit unsigned integer. My primary focus is to find an algorithm that works well across x86 and ARM platforms with an eye towards applicability beyond that. To first order, I am trying to avoid memory operations (which could be expensive), so I am looking for bit-twiddly approaches while avoiding tables. I am also trying to avoid potentially expensive operations such as branches and multiplies, and minimize the number of operations and registers used.

            The ISO-C99 code below captures the eight variants I tried so far. It includes a framework for exhaustive test. I bolted onto this some crude execution time measurement which seems to work well enough to get a first performance impression. On the few platforms I tried (all with fast integer multiplies) the variants WARREN_MUL_SHR_2, WARREN_MUL_SHR_1, and DIGIT_SUM_CARRY_OUT_1 seem to be the most performant. My experiments show that the x86, ARM, PowerPC and MIPS compilers I tried at Compiler Explorer all make very good use of platform-specific features such as three-input LEA, byte-expansion instructions, multiply-accumulate, and instruction predication.

            The variant NAIVE_USING_DIV uses an integer division, back-multiply with the divisor followed by subtraction. This is the baseline case. Modern compilers know how to efficiently implement the unsigned integer division by 255 (via multiplication) and will use a discrete replacement for the backmultiply where appropriate. To compute modulo base-1 one can sum base digits, then fold the result. For example 3334 mod 9: sum 3+3+3+4 = 13, fold 1+3 = 4. If the result after folding is base-1, we need to generate 0 instead. DIGIT_SUM_THEN_FOLD uses this method.

            A. Cockburn, "Efficient implementation of the OSI transport protocol checksum algorithm using 8/16-bit arithmetic", ACM SIGCOMM Computer Communication Review, Vol. 17, No. 3, July/Aug. 1987, pp. 13-20

            showed a different way of adding digits modulo base-1 efficiently in the context of a checksum computation modulo 255. Compute a byte-wise sum of the digits, and after each addition, add any carry-out from the addition as well. So this would be an ADD a, b, ADC a, 0 sequence. Writing out the addition chain for this using base 256 digits it becomes clear that the computation is basically a multiply with 0x0101 ... 0101. The result will be in the most significant digit position, except that one needs to capture the carry-out from the addition in that position separately. This method only works when a base digit comprises 2k bits. Here we have k=3. I tried three different ways of remapping a result of base-1 to 0, resulting in variants DIGIT_SUM_CARRY_OUT_1, DIGIT_SUM_CARRY_OUT_2, DIGIT_SUM_CARRY_OUT_3.

            An intriguing approach to computing modulo-63 efficiently was demonstrated by Joe Keane in the newsgroup comp.lang.c on 1995/07/09. While thread participant Peter L. Montgomery proved the algorithm correct, unfortunately Mr. Keane did not respond to requests to explain its derivation. This algorithm is also reproduced in H. Warren's Hacker's Delight 2nd ed. I was able to extend it, in purely mechanical fashion, to modulo-127 and modulo-255. This is the (appropriately named) KEANE_MAGIC variant. Update: Since I originally posted this question, I have worked out that Keane's approach is basically a clever fixed-point implementation of the following: return (uint32_t)(fmod (x * 256.0 / 255.0 + 0.5, 256.0) * (255.0 / 256.0));. This makes it a close relative of the next variant.

            Henry S. Warren, Hacker's Delight 2nd ed., p. 272 shows a "multiply-shift-right" algorithm, presumably devised by the author themself, that is based on the mathematical property that n mod 2k-1 = floor (2k / 2k-1 * n) mod 2k. Fixed point computation is used to multiply with the factor 2k / 2k-1. I constructed two variants of this that differ in how they handle the mapping of a preliminary result of base-1 to 0. These are variants WARREN_MUL_SHR_1 and WARREN_MUL_SHR_2.

            Are there algorithms for modulo-255 computation that are even more efficient than the three top contenders I have identified so far, in particular for platforms with slow integer multiplies? An efficient modification of Keane's multiplication-free algorithm for the summing of four base 256 digits would seem to be of particular interest in this context.

            ...

            ANSWER

            Answered 2021-Jun-22 at 05:07

            Here’s my sense of how the fastest answers work. I don’t know yet whether Keane can be improved or easily generalized.

            Given an integer x ≥ 0, let q = ⌊x/255⌋ (in C, q = x / 255;) and r = x − 255 q (in C, r = x % 255;) so that q ≥ 0 and 0 ≤ r < 255 are integers and x = 255 q + r.

            Adrian Mole’s method

            This method evaluates (x + ⌊x/255⌋) mod 28 (in C, (x + x / 255) & 0xff), which equals (255 q + r + q) mod 28 = (28 q + r) mod 28 = r.

            Henry S. Warren’s method

            Note that x + ⌊x/255⌋ = ⌊x + x/255⌋ = ⌊(28/255) x⌋, where the first step follows from x being an integer. This method uses the multiplier (20 + 2−8 + 2−16 + 2−24 + 2−32) instead of 28/255, which is the sum of the infinite series 20 + 2−8 + 2−16 + 2−24 + 2−32 + …. Since the approximation is slightly under, this method must detect the residue 28 − 1 = 255.

            Joe Keane’s method

            The intuition for this method is to compute y = (28/255) x mod 28, which equals (28/255) (255 q + r) mod 28 = (28 q + (28/255) r) mod 28 = (28/255) r, and return y − y/28, which equals r.

            Since these formulas don’t use the fact that ⌊(28/255) r⌋ = r, Keane can switch from 28 to 210 for two guard bits. Ideally, these would always be zero, but due to fixed-point truncation and an approximation for 210/255, they’re not. Keane adds 2 to switch from truncation to rounding, which also avoids the special case in Warren.

            This method sort of uses the multiplier 22 (20 + 2−8 + 2−16 + 2−24 + 2−32 + 2−40) = 22 (20 + 2−16 + 2−32) (20 + 2−8). The C statement x = (((x >> 16) + x) >> 14) + (x << 2); computes x′ = ⌊22 (20 + 2−16 + 2−32) x⌋ mod 232. Then ((x >> 8) + x) & 0x3ff is x′′ = ⌊(20 + 2−8) x′⌋ mod 210.

            I don’t have time right now to do the error analysis formally. Informally, the error interval of the first computation has width < 1; the second, width < 2 + 2−8; the third, width < ((2 − 2−8) + 1)/22 < 1, which allows correct rounding.

            Regarding improvements, the 2−40 term of the approximation seems not necessary (?), but we might as well have it unless we can drop the 2−32 term. Dropping 2−32 pushes the approximation quality out of spec.

            Source https://stackoverflow.com/questions/68074457

            QUESTION

            Webassembly: possible to have shared objects?
            Asked 2021-May-30 at 15:07

            I am wondering if, using C (or C++ or Rust) and javascript, I am able to do CRUD operations to a shared data object. Using the most basic example, here would be an example or each of the operations:

            ...

            ANSWER

            Answered 2021-May-24 at 08:54

            Yes, this is possible.

            WebAssembly stores objects within linear memory, a contiguous array of bytes that the module can read and write to. The host environment (typically JavaScript within the web browser) can also read and write to linear memory, allowing it to access the objects that the WebAssembly modules stores there.

            There are two challenges here:

            1. How do you find where your WebAssembly module has stored an object?
            2. How is the object encoded?

            You need to ensure that you can read and write these objects from both the WebAssembly module and the JavaScript host.

            I'd pick a known memory location, and a known serialisation format and use that to read/write from both sides.

            Source https://stackoverflow.com/questions/67655485

            QUESTION

            Record cannot get parameter names from constructors?
            Asked 2021-Apr-27 at 18:11

            Looking to see how to use Records with reflection under Java 16 (and 15 same behavior)

            ...

            ANSWER

            Answered 2021-Apr-11 at 18:25

            This is working as designed. Parameter names in Java APIs are, in general, not something you can rely on to not change; they are an implementation detail, and by default, the compiler will not retain them in the classfile.

            For the canonical constructor of a record, the parameter names must match the component names, and those are considered a part of the classes public API, and are therefore considered stable. So the compiler retains them in the classfile and reflection dutifully serves them up. The canonical constructor of a record is mandatory, and its form is specified by the language, so it is special in this way.

            For the other constructors, neither the constructors nor the the parameter names have the same significance, so these are treated like ordinary members for purposes of the ParameterNames classfile attribute.

            Source https://stackoverflow.com/questions/67038058

            QUESTION

            Is there a way to print Runes as individual characters?
            Asked 2021-Apr-23 at 13:55
            Program's Purpose: Rune Cipher Final Edit:

            I have now (thanks to the Extremely Useful answers provided by the Extremely Amazing People) Completed the project I've been working on; and - for future readers I am also providing the full code.

            Again, This wouldn't have been possible without all the help I got from the guys below, thanks to them - once again!

            Original code on GitHub

            Code

            (Shortened down a bit)

            ...

            ANSWER

            Answered 2021-Feb-27 at 22:33

            To hold a character outside of the 8-bit range, you need a wchar_t (which isn't necessarily Unicode). Although wchar_t is a fundamental C type, you need to #include to use it, and to use the wide character versions of string and I/O functions (such as putwc shown below).

            You also need to ensure that you have activated a locale which supports wide characters, which should be the same locale as is being used by your terminal emulator (if you are writing to a terminal). Normally, that will be the default locale, selected with the string "".

            Here's a simple equivalent to your Python code:

            Source https://stackoverflow.com/questions/66401017

            QUESTION

            Double precision is different in different languages
            Asked 2021-Apr-02 at 18:23

            I'm experimenting with the precision of a double value in various programming languages.

            My programs main.c ...

            ANSWER

            Answered 2021-Jan-15 at 19:43

            The differences you're seeing are in how you print out the data, not in the data itself.

            As I see it, we have two problems here. One is that you're not consistently specifying the same precision when you print out the data in each language.

            The second is that you're printing the data out to 17 digits of precision, but at least as normally implemented (double being a 64-bit number with a 53-bit significand) a double really only has about 15 decimal digits of precision.

            So, while (for example) C and C++ both require that your result be rounded "correctly", once you go beyond the limits of precision it's supposed to support, they can't guarantee much about producing truly identical results in every possible case.

            But that's going to affect only how the result looks when you print it out, not how it's actually stored internally.

            Source https://stackoverflow.com/questions/65742059

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install printf

            You can download it from GitHub.

            Support

            Unsigned hexadecimal integer (lowercase). Unsigned hexadecimal integer (uppercase). Scientific-notation (exponential) floating point. Scientific or decimal floating point. A % followed by another % character will write a single %.
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/mpaland/printf.git

          • CLI

            gh repo clone mpaland/printf

          • sshUrl

            git@github.com:mpaland/printf.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link

            Explore Related Topics

            Consider Popular C Libraries

            linux

            by torvalds

            scrcpy

            by Genymobile

            netdata

            by netdata

            redis

            by redis

            git

            by git

            Try Top Libraries by mpaland

            avl_array

            by mpalandC++

            sqlitepp

            by mpalandC++

            vic

            by mpalandC++

            mipher

            by mpalandTypeScript

            bsonfy

            by mpalandTypeScript