poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Challenges of adding octal and hexadecimal escape sequences in strin


From: Jose E. Marchesi
Subject: Re: Challenges of adding octal and hexadecimal escape sequences in strings
Date: Sat, 31 Oct 2020 13:44:30 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

>> On Fri, Oct 30, 2020 at 05:51:44PM +0100, Jose E. Marchesi wrote:
>>> 
>>> I don't think that is the desired behavior.  If we define Poke strings
>>> as NULL-terminated, it is obvious they are not to contain any NULL
>>> byte.  Now, we can achieve that by two ways:
>>> 
>>> a) By doing what we do now, i.e to ignore any part of the string after a
>>>    NULL character, in case one is inserted, or
>>> 
>>> b) To emit an error whenever a 0 byte is attempted to be stored in a
>>>    string value.
>>> 
>>> Supposing we wanted to switch to b), at the moment the only ways to
>>> create a string value in Poke are:
>>> 
>>> b1) Using a string literal, and
>>> b2) using a cast from uint<8> to string
>>> 
>>> The first case is easy to implement: just emit a compile-time error if a
>>> string literal contains a null character.
>>> 
>>> For the second case we have two choices: either to raise an exception
>>> when `8UB as string' is executed, or to keep the current behavior of
>>> generating an empty string "", but the latter would be an exception to
>>> the rule.
>>> 
>>> That's why I prefer a) to b): it is more orthogonal, and can be
>>> explained by a single rule without needing any exceptions to the rule.
>>> Also, it comes handy to shorten strings :D
>>
>> What about a third way:
>>
>> c) Keep Poke strings as NULL-terminated. Treat using of NULL character in 
>> string
>>    literals as compilation error.
>>
>> The user cannot access data beyond the first NULL character, and having bytes
>> beyond that character doesn't make any sense.
>
> Isn't that a subset of b) above?

I would like to add, that I don't find the current situation (i.e. a))
confusing at all.

On the opposite, it can't be simpler: regardless of how you construct a
string (be it using a literal with escape sequences, or mapping it on an
IO space) the resulting string spans until the first NULL character
found.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]