-
Code: Hello World!
03/29/2016 at 11:06 • 1 commentLet's look at Hello World with both printf and reprintf. Both calls produce identical output:
1 printf("%s", "Hello World!\n"); 2 reprintf("\fdp", "Hello World!\n");
In line 1,
- '%' is an escape character directing the printf interpreter to read the following characters as format parameters.
- The single format parameter is 's', which corresponds to the English word "string".
- The type of input string is assumed to be ASCII, UTF-8, or whatever is configured for your locale and terminated with a null character.
- The output format of the string is also locale dependent. Note that on Windows or OSX, the preferred output is in wide strings
In line 2
- '\f' is the escape character directing reprintf to print human readable formatted output.
- 'd' indicates that the input is a string of null terminated characters. The reason for 'd' is that Strings occupy offset 4 in the Input Types section in the ASCII table (see diagram from previous log).
- 'p' indicates 8-bit character encoding, specifically UTF-8.
Though reprintf requires 2 extra characters for Hello World, there is more clarity to the formatting behaviour in reprint.
- '%' is just a normal character in reprint. Escaping should be done with, well, THE escape character '\' (as in '\n')
- Character byte size is exactly defined. Change 'p' to 'q' for a 16-bit character string, 'r' for a 32 bit character string, or 'w' for the wstring_t type. These other characters are just other entries in the Input Sizes section of the ASCII table.
- There are no external dependencies on locale.
-
Design: Working on describing reprint
08/13/2015 at 21:01 • 0 commentsHalf the work of reprint seems to be able to clearly communicate what it is (not that I have gotten much feedback from anyone). So hopefully a diagram will help.
-
Design: Code and semantic cleanups
08/10/2015 at 07:19 • 0 commentsWhen specifying a pointer to data, the data may be packed in one of two ways: tightly backed (no padding) and C struct{} style padding. Originally I had separate functions for choosing which padding to use (e.g. reprintf_struct vs reprintf_packed) but adding some packing directive flags to the syntax makes these extra functions unnecessary.
The test program "checker" reads the test data in JSON format and tightly packs the data, which made testing this feature very straightforward.
-
reprint on hackaday.io
08/03/2015 at 05:47 • 0 commentsI've been working on reprint on and off for the past few years. I don't have all the time necessary to finish it myself, so I am publishing hoping that there is interest in it. Most programmers will say printf works just fine, but I say the better way is reprint.