git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3] CodingGuidelines: use octal escapes, not hex

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 14, 2023, 21:54 UTC
Message-ID
<xmqqo7lhwvyt.fsf@gitster.g>
In-Reply-To
<20230614213145.475607-1-jonathantanmy@google.com>
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.
Previous: Jonathan Tan
Message 4 of 4 in “CodingGuidelines: use octal escapes, not hex”
  1. CodingGuidelines: use octal escapes, not hexJonathan Tan, Jun 14, 2023
  2. Junio C HamanoJun 14, 2023
  3. CodingGuidelines: use octal escapes, not hexJonathan Tan, Jun 14, 2023
  4. Junio C HamanoJun 14, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.