A common pattern in output is to indent a line based on its depth in a hierarchy (i.e., JSON or XML, or function depth when debugging). Though the output is the same, the method is different between reprint and printf:
/* Indentation with N spaces on reprint and printf */
int N = 10;
reprintf("\f=ep", N, ' ');
printf("%*s", N, "");
- In printf, we use the left pad approach but put ε, (the empty string), as the value to be padded. In printf, padding is hardcoded to the ' ' character resulting in N spaces.
- In reprint, the command is to repeatedly print a specific character N times. The syntax breaks down as follows:
- \f: Formatted output field header
- =: Store the corresponding integer in the '=' register (register 4).
- ep: The data input type is a character, 8 bits.
In reprint, numeric parameters are specified by the user as loading register values (much like a microprocessor). The numeric value does not have any meaning without a corresponding input type. So when reprint parses 'e', the meaning of the register is understood to be character repetition.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.