Message ID | 20230614213145.475607-1-jonathantanmy@google.com (mailing list archive) |
---|---|
State | Accepted |
Commit | f0b68f0546a44e2bc3a764bd75b3aa4418c01601 |
Headers | show |
Series | [v3] CodingGuidelines: use octal escapes, not hex | expand |
Jonathan Tan <jonathantanmy@google.com> writes: > Extend the shell-scripting section of CodingGuidelines to suggest octal > escape sequences (e.g. "\302\242") over hexadecimal (e.g. "\xc2\xa2") > since the latter can be a source of portability problems. Sounds good. On a typical GNU system, /usr/bin/printf as well as printf built into bash groks "\x<hex>" escapes in its format string, but we cannot depend on it because POSIX does not require support for "\x<hex>", and printf built into dash indeed does not. It is a good idea to stress that this is specifically about the format string (in other words, nothing magical happens when using octal or hex escapes in say "printf '%s\n' '\302\242'"). > + - Use octal escape sequences (e.g. "\302\242"), not hexadecimal (e.g. > + "\xc2\xa2") in printf format strings, since hexadecimal escape > + sequences are not portable. Will queue. Thanks.
diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines index 003393ed16..39ef53c237 100644 --- a/Documentation/CodingGuidelines +++ b/Documentation/CodingGuidelines @@ -188,6 +188,10 @@ For shell scripts specifically (not exhaustive): hopefully nobody starts using "local" before they are reimplemented in C ;-) + - Use octal escape sequences (e.g. "\302\242"), not hexadecimal (e.g. + "\xc2\xa2") in printf format strings, since hexadecimal escape + sequences are not portable. + For C programs: