View Issue Details

IDProjectCategoryView StatusLast Update
0001413Issue 8 draftsShell and Utilitiespublic2024-06-11 09:12
Reporterphilip-guenther Assigned To 
PrioritynormalSeverityObjectionTypeError
Status ClosedResolutionAccepted As Marked 
Product VersionDraft 1.1 
NamePhilip Guenther
OrganizationOpenBSD
User Reference
Sectionprintf's APPLICATION USAGE
Page Number3038
Line Number102845 - 102848
Final Accepted TextSee 0001413:0005276
Summary0001413: incorrect description of how a hexadecimal character constant can be terminated in ISO C
DescriptionThe text says:

> In the ISO C standard, the "##" concatenation
> operator can be used to terminate a constant and follow it with a hexadecimal character to be
> written. In the shell, concatenation occurs before the printf utility has a chance to parse the end
> of the hexadecimal constant.

The ## operator is neither necessary nor sufficient. All that's needed is use of string literal concatenation.

Indeed, this was an example in (at least) drafts of the C99 standard, in the specification of string literals lexical elements:

# EXAMPLE This pair of adjacent character string literals
#
# "\x12" "3"
#
# produces a single character string literal containing the two characters whose values are '\x12' and '3',
# because escape sequences are converted into single members of the execution character set just prior to
# adjacent string literal concatenation.
Desired ActionReplace the sentence:
  In the ISO C standard, the "##" concatenation operator can be used to terminate a constant and follow it with a hexadecimal character to be written.

With something like:
  In the ISO C standard, the constant and its following hexadecimal character can be placed in separate string literals as escape sequence processing occurs before string literal concatenation.

(I'm not really happy with that phrasing; better suggestions welcome!)
Tagsissue8

Relationships

child of 0000249 Closedajosey 1003.1(2008)/Issue 7 Add standard support for $'...' in shell 

Activities

nick

2021-02-18 17:12

manager   bugnote:0005248

(TC2 page and line numbers) change page 3115 line 104182-104185, after 0000249 is resolved:
        
In the ISO C standard, the "##" concatenation operator can be used to terminate a constant and follow it with a hexadecimal character to be written. In the shell, concatenation occurs before the printf utility has a chance to parse the end of the hexadecimal constant.

to:
      
Note however that a <tt>$'...'</tt> string may be used to embed hexadecimal constants in a format string in a portable way.

mirabilos

2021-03-15 20:53

reporter   bugnote:0005274

I don’t quite get this. In $'…' strings, \x123 is also unspecified (some current implementations make this into \x23 or even \u0123).

Maybe as $'\x12'3 or, more generally, $'\x12'$'3' … hmm, but that’s not obvious from the wording.

geoffclare

2021-03-16 10:01

manager   bugnote:0005276

I see your point. Perhaps it would be better to keep the part about concatenation (with corrected wording) and say that in the shell $'...' can be used in a similar way. Something like:

On 2018 edition page 3115 line 104182-104185, after 0000249 is resolved change:
In the ISO C standard, the "##" concatenation operator can be used to terminate a constant and follow it with a hexadecimal character to be written. In the shell, concatenation occurs before the printf utility has a chance to parse the end of the hexadecimal constant.
to:
In the ISO C standard, string literal concatenation can be used to terminate a constant and follow it with a hexadecimal character to be written. In the shell, similar concatenation can be done using <tt>$'...'</tt> so that the shell converts the hexadecimal sequence before it executes printf.

geoffclare

2022-10-21 09:55

manager   bugnote:0006011

Now that bug 0000249 has been resolved, this bug can be revisited.

Issue History

Date Modified Username Field Change
2020-10-24 22:01 philip-guenther New Issue
2020-10-24 22:01 philip-guenther Name => Philip Guenther
2020-10-24 22:01 philip-guenther Organization => OpenBSD
2020-10-24 22:01 philip-guenther Section => printf's APPLICATION USAGE
2020-10-24 22:01 philip-guenther Page Number => 3038
2020-10-24 22:01 philip-guenther Line Number => 102845 - 102848
2021-02-18 17:11 nick Relationship added child of 0000249
2021-02-18 17:12 nick Note Added: 0005248
2021-02-18 17:13 nick Status New => Resolution Proposed
2021-02-18 17:13 nick Resolution Open => Accepted As Marked
2021-02-18 17:14 nick Final Accepted Text => See 0001413:0005248
2021-02-18 17:15 nick Tag Attached: issue8
2021-03-15 20:53 mirabilos Note Added: 0005274
2021-03-16 10:01 geoffclare Note Added: 0005276
2022-10-21 09:55 geoffclare Note Added: 0006011
2022-10-21 09:55 geoffclare Status Resolution Proposed => Under Review
2022-10-21 10:03 geoffclare Resolution Accepted As Marked => Reopened
2022-11-03 15:24 geoffclare Final Accepted Text See 0001413:0005248 => See 0001413:0005276
2022-11-03 15:24 geoffclare Status Under Review => Resolved
2022-11-03 15:24 geoffclare Resolution Reopened => Accepted As Marked
2022-11-30 16:46 geoffclare Status Resolved => Applied
2024-06-11 09:12 agadmin Status Applied => Closed