Saturday, July 3, 2021

Digest for comp.lang.c++@googlegroups.com - 25 updates in 3 topics

olcott <NoOne@NoWhere.com>: Jul 03 10:19AM -0500

*Halting problem undecidability and infinitely nested simulation*
When the halt decider bases its halt status decision simulating its
input then the conventional halting problem proof undecidability
counter-example templates can be correctly decided as inputs that never
halt. They will never halt because they specify infinitely nested
simulation to any simulating halt decider.
 
Because a simulating halt decider must always abort the simulation of
every input that never halts its halt deciding criteria must be adapted.
[ Does the input halt on its input? ] must become [ Does the input halt
without having its simulation aborted? ] This change is required because
every input to a simulating halt decider either halts on its own or
halts because its simulation has been aborted.
 
The standard pseudo-code halting problem template "proved" that the
halting problem could never be solved on the basis that neither value of
true (halting) nor false (not halting) could be correctly returned to
the confounding input.
 
// Simplified Linz Ĥ (Linz:1990:319)
void P(u32 x)
{
u32 Input_Halts = H(x, x);
if (Input_Halts)
HERE: goto HERE;
}
 
int main()
{
u32 Input_Halts = H((u32)P, (u32)P);
Output("Input_Halts = ", Input_Halts);
}
 
This problem is overcome on the basis that a simulating halt decider
would abort the simulation of its input before ever returning any value
to this input. It aborts the simulation of its input on the basis that
its input specifies what is essentially infinite recursion (infinitely
nested simulation) to any simulating halt decider.
 
The x86utm operating system was created so that the halting problem
could be examined concretely in the high level language of C and x86.
When examining the halting problem this way every detail can be
explicitly specified. UTM tape elements are 32-bit unsigned integers.
 
H analyzes the (currently updated) stored execution trace of its x86
emulation of P(P) after it simulates each instruction of input (P, P).
As soon as a non-halting behavior pattern is matched H aborts the
simulation of its input and decides that its input does not halt.
 
*This is the sound deductive inference (proof) that H(P,P)==0 is correct*
 
Premise(1) (axiom) Every computation that never halts unless its
simulation is aborted is a computation that never halts. This verified
as true on the basis of the meaning of its words.
 
Premise(2) (verified fact) The simulation of the input to H(P,P) never
halts without being aborted is a verified fact on the basis of its x86
execution trace. (shown below).
 
When the simulator determines whether or not it must abort the
simulation of its input based on the behavior of its input the simulator
only acts as an x86 emulator thus has no effect on the behavior of its
input. This allows the simulator to always ignore its own behavior.
 
Conclusion(3) From the above true premises it necessarily follows that
simulating halt decider H correctly reports that its input: (P,P) never
halts.
 
 
 
 
Halting problem undecidability and infinitely nested simulation
https://www.researchgate.net/publication/351947980_Halting_problem_undecidability_and_infinitely_nested_simulation
 
 
--
Copyright 2021 Pete Olcott
 
"Great spirits have always encountered violent opposition from mediocre
minds." Einstein
olcott <NoOne@NoWhere.com>: Jul 03 11:19AM -0500

On 7/3/2021 10:56 AM, Richard Damon wrote:
>> to this input.
 
> But what does aborting the simulation have to do with returning the
> answer to the caller. THEY ARE DIFFERENT.
 
void P(u32 x)
{
u32 Input_Halts = H(x, x);
if (Input_Halts)
HERE: goto HERE;
}
 
int main()
{
u32 Input_Halts = H((u32)P, (u32)P);
Output("Input_Halts = ", Input_Halts);
}
 
When the called is calling H in infinitely nested simulation
 
IN THE ABOVE C COMPUTATION NOT ANY OTHER COMPUTATION
IN THE ABOVE C COMPUTATION NOT ANY OTHER COMPUTATION
IN THE ABOVE C COMPUTATION NOT ANY OTHER COMPUTATION
IN THE ABOVE C COMPUTATION NOT ANY OTHER COMPUTATION
 
IN THE ABOVE C COMPUTATION NOT ANY OTHER COMPUTATION
IN THE ABOVE C COMPUTATION NOT ANY OTHER COMPUTATION
IN THE ABOVE C COMPUTATION NOT ANY OTHER COMPUTATION
IN THE ABOVE C COMPUTATION NOT ANY OTHER COMPUTATION
 
The simulating halt decider H must abort the simulation of its input in
the computation H(P,P) before returning any value to P.
 
IN THE ABOVE C COMPUTATION NOT ANY OTHER COMPUTATION
IN THE ABOVE C COMPUTATION NOT ANY OTHER COMPUTATION
IN THE ABOVE C COMPUTATION NOT ANY OTHER COMPUTATION
IN THE ABOVE C COMPUTATION NOT ANY OTHER COMPUTATION
 
IN THE ABOVE C COMPUTATION NOT ANY OTHER COMPUTATION
IN THE ABOVE C COMPUTATION NOT ANY OTHER COMPUTATION
IN THE ABOVE C COMPUTATION NOT ANY OTHER COMPUTATION
IN THE ABOVE C COMPUTATION NOT ANY OTHER COMPUTATION
 
> Engineering concept of execution context.
 
> After H aborts the simulation, it needs to do something. By its
> requriements, it needs to return that answer to its caller.
 
H does return a value of 0 to main(). H does not return any value to the
simulated P that calls H in infinitely nested simulation.
 
> When it does, it tells that caller that it thinks that P(P) is
> non-Halting, but when it does that to the caller P, that P then halts,
> showing that the answer it gave was wrong.
 
Because a simulating halt decider must always abort the simulation of
every input that never halts its halt deciding criteria must be adapted.
 
Does the input halt on its input?
must become
Does the input halt without having its simulation aborted?
 
This change is required because every input to a simulating halt decider
either halts on its own or halts because its simulation has been aborted.
 
> The FUNDAMENTAL definition of Halting is what the machine does when run
> as a machine with the given input. It is shown that P(P) does Halt (and
> you admit this at times) thus P(P) IS a HALTING computation, by definition.
 
That definition simply ignores simulating halt deciders. The fatal
mistake of the halting problem proofs is they simply ignoring simulating
halt deciders.
 
> The non-Halting answer is wrong, by definition.
 
The non-halting answer is correct the definition must be adapted.
 
> Any 'logic' that 'proves' otherwise is by definition wrong or at least
> shows the logic is inconsistent.
 
According to your incorrect reasoning a simulating halt decider must
always report true because all of its inputs either halt own their own
or are aborted.
 
Because people that are not dumber than a box of rocks do understand
that computations that only halt because they were aborted are
computations that never halt there is agreement that your reasoning is
incorrect.
 
Ben and Kaz both agree. that computations that only halt because their
simulation was aborted are non-halting computations.
 
 
--
Copyright 2021 Pete Olcott
 
"Great spirits have always encountered violent opposition from mediocre
minds." Einstein
Bonita Montero <Bonita.Montero@gmail.com>: Jul 03 06:28PM +0200

You are off-topic in comp.lang.c/c++.
Nothing what you say is especially related to C or C++.
Stop posting here.
olcott <NoOne@NoWhere.com>: Jul 03 11:51AM -0500

On 7/3/2021 11:28 AM, Bonita Montero wrote:
> You are off-topic in comp.lang.c/c++.
> Nothing what you say is especially related to C or C++.
> Stop posting here.
 
It is 100% totally related to software engineering in C.
The first 8 pages of my paper are only about software engineering in C.
 
Halting problem undecidability and infinitely nested simulation
 
https://www.researchgate.net/publication/351947980_Halting_problem_undecidability_and_infinitely_nested_simulation
 
 
--
Copyright 2021 Pete Olcott
 
"Great spirits have always encountered violent opposition from mediocre
minds." Einstein
Bonita Montero <Bonita.Montero@gmail.com>: Jul 03 07:18PM +0200

> It is 100% totally related to software engineering in C.
 
It's related to programming in general.
So you shouldn't post in groups related to specific languages.
olcott <NoOne@NoWhere.com>: Jul 03 12:19PM -0500

On 7/3/2021 12:18 PM, Bonita Montero wrote:
>> It is 100% totally related to software engineering in C.
 
> It's related to programming in general.
> So you shouldn't post in groups related to specific languages.
 
It is a specific software engineering problem in the C programming
language. The C source code is provided.
 
--
Copyright 2021 Pete Olcott
 
"Great spirits have always encountered violent opposition from mediocre
minds." Einstein
Bonita Montero <Bonita.Montero@gmail.com>: Jul 03 07:33PM +0200

>> So you shouldn't post in groups related to specific languages.
 
> It is a specific software engineering problem in the C programming
> language. The C source code is provided.
 
You don't don't discuss any C/C++-specific issues.
comp.theory is the only NG that fits.
Stop posting in comp.lang.c/c++.
You're a off-topic-terrorist.
"Alf P. Steinbach" <alf.p.steinbach@gmail.com>: Jul 03 03:30AM +0200

On 2 Jul 2021 22:15, James Kuyper wrote:
> the U prefix.
 
> I have a feeling that there's a misunderstanding somewhere in this
> conversation, but I'm not sure yet what it is.
 
Juha is concerned about the compiler assuming some other source code
encoding than the actual one.
 
The implementation defined encoding of `wchar_t`, where in practice the
possibilities as of 2021 are either UTF-16 or UTF-32, doesn't matter.
 
A correct source code encoding assumption can be guaranteed by simply
statically asserting that the basic execution character set is UTF-8, as
I showed in my original answer in this thread.
 
 
 
>> the stuff between the quotation marks in the source code will use
>> whatever encoding (ostensibly but not assuredly UTF-8), which the
 
> I don't understand why you think that the source code encoding matters.
 
It matters because if the compiler assumes wrong, and Visual C++
defaults to assuming Windows ANSI when no other indication is present
and it's not forced by options, then one gets incorrect literals.
 
Which may or may not be caught by unit testing.
 
 
> those encodings are for the characters {'u', '""', '\\', 'x', 'C', '2',
> '\\', 'x', 'A', '9', '"'}, any fully conforming implementation must give
> you the standard defined behavior for u"\xC2\xA9".
 
Consider:
 
#include <iostream>
using std::cout, std::hex, std::endl;
 
auto main() -> int
{
const char16_t s16[] = u"\xC2\xA9";
for( const int code: s16 ) {
if( code ) { cout << hex << code << " "; }
}
cout << endl;
}
 
The output of this program, i.e. the UTF-16 encoding values in `s16`, is
 
c2 a9
 
Since Unicode is an extension of Latin-1 the UTF-16 interpretation of
`\xC2` and `xA9` is as Latin-1 characters, respectively "Â" and (not a
coincidence) "©" according to my Windows 10 console in codepage 1252.
 
Which is not the single "©" that an UTF-8 interpretation gives.
 
 
[snip]
 
 
- Alf
James Kuyper <jameskuyper@alumni.caltech.edu>: Jul 03 12:44AM -0400

On 7/2/21 9:30 PM, Alf P. Steinbach wrote:
>> the U prefix.
 
>> I have a feeling that there's a misunderstanding somewhere in this
>> conversation, but I'm not sure yet what it is.
 
I now have a much better idea what the misunderstanding is. See below.
 
> A correct source code encoding assumption can be guaranteed by simply
> statically asserting that the basic execution character set is UTF-8, as
> I showed in my original answer in this thread.
 
The encoding of the basic execution character set is irrelevant if the
string literals are prefixed with u8, u, or U, and use only valid escape
sequences to specify members of the extended character set. The encoding
for such literals is explicitly mandated by the standard. Are you (or
he) worrying about a failure to conform to those mandates?
 
...
 
> It matters because if the compiler assumes wrong, and Visual C++
> defaults to assuming Windows ANSI when no other indication is present
> and it's not forced by options, then one gets incorrect literals.
 
Even when u8, u or U prefixes are specified?
 
...
> }
 
> The output of this program, i.e. the UTF-16 encoding values in `s16`, is
 
> c2 a9
 
 
Yes, that's precisely what the C++ standard mandates, regardless of the
encoding of the source character set. Which is why I mistakenly thought
that's what he was trying to do.
 
> `\xC2` and `xA9` is as Latin-1 characters, respectively "Â" and (not a
> coincidence) "©" according to my Windows 10 console in codepage 1252.
 
> Which is not the single "©" that an UTF-8 interpretation gives.
 
OK - it had not occurred to me that he was trying to encode "©", since
that is not the right way to do so. In a sense, I suppose that's the
point you're making.
My point is that all ten of the following escape sequences should be
perfectly portable ways of specifying that same code point in each of
three Unicode encodings:
 
UTF-8: u8"\u00A9\U000000A9"
UTF-16: u"\251\xA9\u00A9\U000000A9"
UTF-32: U"\251\xA9\u00A9\U000000A9"
 
Do you know of any implementation which is non-conforming because it
misinterprets any of those escape sequences?
Juha Nieminen <nospam@thanks.invalid>: Jul 03 06:59AM


>> the stuff between the quotation marks in the source code will use
>> whatever encoding (ostensibly but not assuredly UTF-8), which the
 
> I don't understand why you think that the source code encoding matters.
 
Because the source file will most often be a text file using 8-bit
characters and, in these situations most likely (although not assuredly)
using UTF-8 encoding for non-ascii characters.
 
However, when you write:
 
const char16_t *str = u"something";
 
if that "something" contains non-ascii characters, which in this case will
be (usually) UTF-8 encoded in this source code, the compiler will have to
interpret that UTF-8 string and convert it to UTF-16 for the output
binary.
 
So the problem is the same as with wchar_t: How does the compiler know
which encoding is being used in this source file? It needs to know that
since it has to generate an UTF-16 string literal into the output binary
from those characters appearing in the source code.
 
> When using the u8 prefix, UTF-8 encoding is guaranteed, for which every
> codepoint from U+0000 to U+007F is represented by a single character
> with a numerical value matching the code point.
 
UTF-8 encoding is guaranteed *for the result*, ie. what the compiler writes
to the output binary. Is it guaranteed to *read* the characters in the
source code between the quotation marks and interpret it as UTF-8?
 
> codepoint from U+0000 to U+D7FF, and from U+E000 to U+FFFF, is
> represented by a single character with a numerical value matching the
> codepoint.
 
Same issue, even more relevantly here.
 
> Do you know of any implementation of C++ that claims to be fully
> conforming, for which that is not the case? If so, how do they justify
> that claim?
 
Visual Studio will, by default (ie. with default project settings after
having created a new project) interpret the source files as Windows-1252
(which is very similar to ISO-Latin-1).
 
This means that when you write L"something" or u"something", if there
are any non-ascii characters between the parentheses, UTF-8 encoded,
then the result will be incorrect. (In order to make Visual Studio do
the correct conversion, you need to specify that the file is UTF-8 encoded
in the project settings).
 
> according to an implementation-defined character encoding. But so long
> as they encode {'\\', 'x', 'C', '2', '\\', 'x', 'A', '9'}, you should
> get the standard-defined behavior for u"\xC2\xA9".
 
Yes, but that's not the correct desired character in UTF-16, only in UTF-8.
You'll get garbage as your UTF-16 string literal.
"Alf P. Steinbach" <alf.p.steinbach@gmail.com>: Jul 03 01:31PM +0200

On 3 Jul 2021 06:44, James Kuyper wrote:
 
> The encoding of the basic execution character set is irrelevant if the
> string literals are prefixed with u8, u, or U, and use only valid escape
> sequences to specify members of the extended character set.
 
Having a handy simple way to guarantee a correct source code encoding
assumption doesn't seem irrelevant to me.
 
On the contrary it's directly a solution to the OP's problem, which to
me appears to be maximally relevant.
 
 
> The encoding
> for such literals is explicitly mandated by the standard. Are you (or
> he) worrying about a failure to conform to those mandates?
 
No, Juha is worrying about the compiler's source code encoding assumption.
 
 
>> defaults to assuming Windows ANSI when no other indication is present
>> and it's not forced by options, then one gets incorrect literals.
 
> Even when u8, u or U prefixes are specified?
 
Yes. As an example, consider
 
const auto& s = u"Blåbær, Mr. Watson.";
 
If the source is UTF-8 encoded, without a BOM or other encoding marker,
and if the Visual C++ compiler is not told to assume UTF-8 source code,
then it will incorrectly assume that this is Windows ANSI encoded.
 
The UTF-8 bytes in the source code will then be interpreted as Windows
ANSI character codes, e.g. as Windows ANSI Western, codepage 1252.
 
The compiler will then see this source code:
 
const auto& s = u"Blåbær, Mr. Watson.";
 
And it will proceeed to encode /that/ string with UTF-8 in the resulting
string value.
 
 
> UTF-32: U"\251\xA9\u00A9\U000000A9"
 
> Do you know of any implementation which is non-conforming because it
> misinterprets any of those escape sequences?
No, they should work. These escapes are an alternative solution to
Juha's problem. However, they lack readability and involve much more
work than necessary, so IMO the thing to do is to assert UTF-8.
 
- Alf
James Kuyper <jameskuyper@alumni.caltech.edu>: Jul 03 08:44AM -0400

On 7/3/21 7:31 AM, Alf P. Steinbach wrote:
> On 3 Jul 2021 06:44, James Kuyper wrote:
>> On 7/2/21 9:30 PM, Alf P. Steinbach wrote:
...
 
>> Even when u8, u or U prefixes are specified?
 
> Yes. As an example, consider
 
> const auto& s = u"Blåbær, Mr. Watson.";
 
The comment that led to this sub-thread was specifically about the
usability of escape sequences to specify members of the extended
character set, and that's the only thing I was talking about. While that
string does contain such members, it contains not a single escape sequence.
 
...
>> misinterprets any of those escape sequences?
> No, they should work. These escapes are an alternative solution to
> Juha's problem. ...
 
They are the only solution that this sub-thread has been about.
 
> ... However, they lack readability and involve much more
> work than necessary, so IMO the thing to do is to assert UTF-8.
 
Those are reasonable concerns. That the system's assumptions about the
source character set would prevent those escapes from working is not.
James Kuyper <jameskuyper@alumni.caltech.edu>: Jul 03 09:03AM -0400

On 7/3/21 2:59 AM, Juha Nieminen wrote:
 
> Because the source file will most often be a text file using 8-bit
> characters and, in these situations most likely (although not assuredly)
> using UTF-8 encoding for non-ascii characters.
 
Every comment I made on this sub-thread was prefaced on the absence of
any actual members of the extended character set - I was talking only
about the feasibility of using escape sequences to specify such members.
 
...
 
> Visual Studio will, by default (ie. with default project settings after
> having created a new project) interpret the source files as Windows-1252
> (which is very similar to ISO-Latin-1).
 
So, that shouldn't cause a problem for escape sequences, which, as a
matter of deliberate design, consist entirely of characters from the
basic source character set.
 
>> get the standard-defined behavior for u"\xC2\xA9".
 
> Yes, but that's not the correct desired character in UTF-16, only in UTF-8.
> You'll get garbage as your UTF-16 string literal.
 
The 'u' mandates UTF-16, which is the only thing that's relevant to the
interpretation of that string literal. That it is the correct pair of
characters, given that UTF-16 has been mandated. Whether or not it's the
intended character depends upon how well your code expresses your
intentions. Alf says that the character that was intended was U+00A9, so
that code does not correctly express that intention. The correct way to
specify it doesn't depend upon the source character set, it only depends
upon the desired encoding of the string. Each of the following ten
escape sequences is a different portably correct ways of expressing that
intention:
 
UTF-8: u8"\u00A9\U000000A9"
UTF-16: u"\251\xA9\u00A9\U000000A9"
UTF-32: U"\251\xA9\u00A9\U000000A9"
Chris Vine <chris@cvine--nospam--.freeserve.co.uk>: Jul 03 02:23PM +0100

On Sat, 3 Jul 2021 06:59:59 +0000 (UTC)
Juha Nieminen <nospam@thanks.invalid> wrote:
[snip]
> which encoding is being used in this source file? It needs to know that
> since it has to generate an UTF-16 string literal into the output binary
> from those characters appearing in the source code.
 
For encodings other than the 96 charcters of the basic source character
set (which map onto ASCII) that the C++ standard requires, this is
implementation defined and the compiler should document it. In the
case of gcc, it documents that the source character set is UTF-8 unless
a different source file encoding is indicated by the -finput-charset
option.
 
With gcc you can also set the narrow execution character set with the
-fexec-charset option. Presumably for any one string literal this can
be overridden by prefixing it with u8, or it wouldn't be consistent
with the standard, but I have never checked whether that is in fact the
case.
 
This is what gcc says about character sets, which is somewhat divergent
from the C and C++ standards:
http://gcc.gnu.org/onlinedocs/cpp/Character-sets.html
 
I doubt this is often relevant. What most multi-lingual programs do is
have source strings in English using the ASCII subset of UTF-8 and
translate to UTF-8 dynamically by reference to the locale. Gnu's
gettext is a quite commonly used implementation of this approach.
"Alf P. Steinbach" <alf.p.steinbach@gmail.com>: Jul 03 04:28PM +0200

On 3 Jul 2021 14:44, James Kuyper wrote:
> On 7/3/21 7:31 AM, Alf P. Steinbach wrote:
>> On 3 Jul 2021 06:44, James Kuyper wrote:
[snippety]
>> work than necessary, so IMO the thing to do is to assert UTF-8.
 
> Those are reasonable concerns. That the system's assumptions about the
> source character set would prevent those escapes from working is not.
 
As far as I know nobody's argued that the source encoding assumption
would prevent any escapes from working.
 
If I understand you correctly your "this sub-thread" about escapes and
universal character designators -- let's just call them all escapes
-- started when you responded to my response Richard Daemon, who had
responded to Juha Niemininen, who wrote:
 
 
[>>]
Does that work for wide string literals? Because I don't think it does.
In other words:
 
std::wstring s = L"Copyright \xC2\xA9 2001-2020";
[<<]
 
 
Richard responded to that:
 
 
[>>]
\x works in wide string literal too, and puts in a character with that
value. The difference is that if the wide string type isn't unicode
encoded then it might get the wrong character in the string.
[<<]
 
 
I responded to Richard:
 
 
[>>]
It gets the wrong characters in the wide string literal, period.
[<<]
 
 
Which it decidedly does.
 
It's trivial to just try it out and see; QED.
 
You responded to that where you snipped Juha's example, indicating some
misunderstanding on your part:
 
 
[>>]
The value of a wide character is determined by the current encoding. For
wide character literals using the u or U prefixes, that encoding is
UTF-16 and UTF-32, respectively, making octal escapes redundant with and
less convenient than the use of UCNs. But as he said, they do work for
such strings.
[<<]
 
 
So, in your mind this sub-thread may have been about whether escape
sequences (including universal character designators) are affected by
the source encoding, but to me it has been about whether Juha's example
yields the desired string, as he correctly surmised that it didn't.
 
And the outer context from the top thread, is about the source
encoding's effect on string literals, which hopefully is now clear.
 
 
- Alf
Richard Damon <Richard@Damon-Family.org>: Jul 03 11:48AM -0400

On 7/3/21 10:28 AM, Alf P. Steinbach wrote:
> It gets the wrong characters in the wide string literal, period.
> [<<]
 
> Which it decidedly does.
 
It puts into the string exactly the characters that you specified, the
character of value 0x00C2 and then the character of value 0x00A9. THAT
is what it says to do. If you meant the \x to mean this is a UTF-8
encode string, why are you expecting that?
 
The one issue with \x is it puts in the characters in whatever encoding
wide strings use, so you can't just assume unicode values unless you are
willing to assume wide string is unicode encoded.
 
 
Juha Nieminen <nospam@thanks.invalid>: Jul 03 04:59PM

> usability of escape sequences to specify members of the extended
> character set, and that's the only thing I was talking about. While that
> string does contain such members, it contains not a single escape sequence.
 
The problem is that the "\xC2\xA9" was presented as a solution to
the compiler wrongly assuming some source file encoding other than UTF-8.
Those two bytes are the UTF-8 encoding of a non-ascii character.
 
In other words, it's explicitly entering the UTF-8 encoding of that
non-ascii character. This works if we are specifying a narrow string
literal (and we want it to be UTF-8 encoded).
 
My point is that it doesn't work for a wide string literal. If you
say L"\xC2\xA9" you will *not* get that non-ascii character you
wanted. Instead, you get two UTF-16 (or UTF-32, depending on
how large wchar_t is) characters which are completely different
from the one you wanted. You essentially get garbage.
Juha Nieminen <nospam@thanks.invalid>: Jul 03 05:06PM

> have source strings in English using the ASCII subset of UTF-8 and
> translate to UTF-8 dynamically by reference to the locale. Gnu's
> gettext is a quite commonly used implementation of this approach.
 
It's quite relevant. For example, if you are writing unit tests for some
library dealing with wide strings (or UTF-16 strings), it's quite common
to write string literals in your tests, so you need to be aware of this
problem: What will work just fine with gcc might not work with Visual
Studio, and your unit test will succeed in one but not the other.
 
The solution offered elsewhere in this tread is the correct way to go,
ie. using the "\uXXXX" escape codes for such string literals, as they
will always be interpreted correctly by the compiler (even if the
readability of the source code suffers as a consequence).
Bonita Montero <Bonita.Montero@gmail.com>: Jul 03 02:45PM +0200

> I just did a line count on our codebase; we have about 1 dynamic
> cast for every 10k lines. Compare with static_cast - 1 in 300.
 
Using dynamic_cast instead of a virtual function call is bad coding.
Richard Damon <Richard@Damon-Family.org>: Jul 03 09:39AM -0400

On 7/3/21 8:45 AM, Bonita Montero wrote:
>> I just did a line count on our codebase; we have about 1 dynamic
>> cast for every 10k lines. Compare with static_cast - 1 in 300.
 
> Using dynamic_cast instead of a virtual function call is bad coding.
 
Incorrect, often to add the virtual function call to get around the need
for the dynamic_cast requires injecting into a class concepts that it
should not be dealing with.
 
As an example, say you have a collection of animals, and you want to
extract all the dogs out of it. You could add to Animal and Dog an isDog
function, (and then need to change Animal again for each new type of
thing you might want get, lousy encapsulation) or you can use a
dynamic_cast to check if this animal is a Dog.
Bonita Montero <Bonita.Montero@gmail.com>: Jul 03 03:53PM +0200


> Incorrect, often to add the virtual function call to get around the need
> for the dynamic_cast requires injecting into a class concepts that it
> should not be dealing with.
 
If you're doing a dynamic_cast you're switching upon the type of the
class. This switching should be better done inside the class with class
-dependent code - with a virtual function call.
 
> function, (and then need to change Animal again for each new type of
> thing you might want get, lousy encapsulation) or you can use a
> dynamic_cast to check if this animal is a Dog.
 
the isDog-function would be faster.
Richard Damon <Richard@Damon-Family.org>: Jul 03 09:59AM -0400

On 7/3/21 9:53 AM, Bonita Montero wrote:
 
> If you're doing a dynamic_cast you're switching upon the type of the
> class. This switching should be better done inside the class with class
> -dependent code - with a virtual function call.
 
Wrong. Application level logic should stay in the application level
code. That is the only scalable option.
 
>> thing you might want get, lousy encapsulation) or you can use a
>> dynamic_cast to check if this animal is a Dog.
 
> the isDog-function would be faster.
 
But then it also needs isCat, isHorse, isSnake, isMammel, isReptile,
and so on.
 
The virtual function method says that you need to change Animal EVERY
TIME you define a new type of animal for the system. This breaks
encapsulation, and binary compatibility, as adding a virtual function to
the base class changes the definition of EVERY subclass to that class.
Bonita Montero <Bonita.Montero@gmail.com>: Jul 03 05:01PM +0200

>> -dependent code - with a virtual function call.
 
> Wrong. Application level logic should stay in the application level
> code. That is the only scalable option.
 
Virtual function calls are more scalable.
 
 
>> the isDog-function would be faster.
 
> But then it also needs isCat, isHorse, isSnake, isMammel, isReptile,
> and so on.
 
Maybe, but that's much faster. Dynamic downcasts are slower.
 
> The virtual function method says that you need to change Animal EVERY
> TIME you define a new type of animal for the system. This breaks
> encapsulation, ...
 
No, it is encapsulation.
Richard Damon <Richard@Damon-Family.org>: Jul 03 11:42AM -0400

On 7/3/21 11:01 AM, Bonita Montero wrote:
 
>> Wrong. Application level logic should stay in the application level
>> code. That is the only scalable option.
 
> Virtual function calls are more scalable.
 
Wrong, the NUMBER of functions needed grows way to fast to be scalable.
It also requires GLOBAL changes in API to implement local algorithms.
 
The act of adding the function could well require recompiling millions
of lines of code over many applications if the base class is commonly use.
 
Imagine what would happen if someone decided that string needed a new
function that made ALL code that uses it to need to be recompiled. This
is an X.0.0 type of change.
 
>> TIME you define a new type of animal for the system. This breaks
>> encapsulation, ...
 
> No, it is encapsulation.
 
No, it BREAKS encapsulation. If adding a new type of animal requires a
change in the animal base, the base is not properly encapsulated.
 
Note, the RTTI interface that is provided built into C++ provides that
encapsulated interface that allows you to detect this without needing to
make these changes.
Bonita Montero <Bonita.Montero@gmail.com>: Jul 03 06:04PM +0200

> Wrong, the NUMBER of functions needed grows way to fast to be scalable.
 
Use an enum and return an enum-value in _one_ function.
That's faster than a dynamical downcast.
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

Friday, July 2, 2021

Digest for comp.lang.c++@googlegroups.com - 16 updates in 3 topics

Juha Nieminen <nospam@thanks.invalid>: Jul 02 05:26AM

> the strings as arrays of char, char16_t, or char32_t, respectively. Such
> literals are guaranteed to be in UTF-8, UTF-16, or UTF-32 encoding,
> respectively.
 
No my choice in this case.
James Kuyper <jameskuyper@alumni.caltech.edu>: Jul 02 01:44AM -0400

On 7/2/21 1:26 AM, Juha Nieminen wrote:
>> literals are guaranteed to be in UTF-8, UTF-16, or UTF-32 encoding,
>> respectively.
 
> No my choice in this case.
 
Recent messages reminded me of Window's strong incentives to use
wchar_t, something I've thankfully had no experience with. As a result,
what I'm about to say may be incorrect - but it seems to me that a
conforming implementation of C++ targeting Windows should have wchar_t
be the same as char16_t, so you should be able to freely use u prefixed
string literals and char16_t with code that needs to be portable to
Windows, but can also be used on other platforms. If your code didn't
need to be portable to other platforms, you could, by definition, rely
upon Window's own guarantees about wchar_t.
Bo Persson <bo@bo-persson.se>: Jul 02 08:33AM +0200

On 2021-07-02 at 07:44, James Kuyper wrote:
> Windows, but can also be used on other platforms. If your code didn't
> need to be portable to other platforms, you could, by definition, rely
> upon Window's own guarantees about wchar_t.
 
The problem is that the language explicitly requires wchar_t to be a
distinct type.
 
Once upon a time it was implemented as a typedef, but that option was
removed already in C++98. Overload resolution and things...
Kli-Kla-Klawitter <kliklaklawitter69@gmail.com>: Jul 02 10:03AM +0200

Am 01.07.2021 um 20:21 schrieb Keith Thompson:
 
>> v1.01 does honor the BOM.
 
> At the risk of giving the impression I'm taking you seriously, the
> oldest version of gcc available from gnu.org is 1.42, released in 1992.
 
No, the oldest gcc-version is v0.9 from March 22, 1987.
Keith Thompson <Keith.S.Thompson+u@gmail.com>: Jul 02 02:31AM -0700

Ralf Goertz <me@myprovider.invalid> writes:
[...]
> b.cc:1:5: warning: null character(s) ignored
 
> etc.
 
> How does that qualify as "gcc honoring the BOM"?
 
On my system, gcc doesn't handle UTF-16 at all, with or without a BOM.
(I don't know whether there's a way to configure it to do so.)
 
It does handle UTF-8 with or without a BOM.
 
$ file b.cpp
b.cpp: C source, UTF-8 Unicode (with BOM) text
$ cat b.cpp
int main() { }
$ hd b.cpp
00000000 ef bb bf 69 6e 74 20 6d 61 69 6e 28 29 20 7b 20 |...int main() { |
00000010 7d 0a |}.|
00000012
$ gcc -c b.cpp
$
 
gcc 9.3.0 on Ubuntu 20.04. (There is, of course, no point in going back
to ancient versions of gcc.)
 
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */
MrSpud_oyCn@92wvlb1hltq4dhc.gov.uk: Jul 02 09:38AM

On Fri, 02 Jul 2021 02:31:24 -0700
>[...]
 
>On my system, gcc doesn't handle UTF-16 at all, with or without a BOM.
>(I don't know whether there's a way to configure it to do so.)
 
Just out of interest, what byte order is the BOM in? Catch 22?
Paavo Helde <myfirstname@osa.pri.ee>: Jul 02 01:52PM +0300


>> On my system, gcc doesn't handle UTF-16 at all, with or without a BOM.
>> (I don't know whether there's a way to configure it to do so.)
 
> Just out of interest, what byte order is the BOM in? Catch 22?
 
This is probably a troll question, but answering anyway: the BOM marker
U+FEFF is in the correct byte order, in both little-endian and
big-endian UTF-16. That's how you tell them apart.
 
The trick is in that the reverse value U+FFFE is not valid Unicode
character, so there is no possibility of mixup. Neither sequence is also
valid UTF-8, to avoid mixup with that.
Juha Nieminen <nospam@thanks.invalid>: Jul 02 11:52AM

> so you should be able to freely use u prefixed
> string literals and char16_t with code that needs to be portable to
> Windows, but can also be used on other platforms.
 
But doesn't that have the exact same problem as in my original post?
In other words, in code like this:
 
const char16_t *str = u"something";
 
the stuff between the quotation marks in the source code will use
whatever encoding (ostensibly but not assuredly UTF-8), which the
compiler needs to convert to UTF-16 at compile time for writing
it to the output binary.
 
Or is it guaranteed that the characters between u" and " will
always be interpreted as UTF-8?
MrSpud_zg8yg@nx8574z6ey2rc0y563k5i2.net: Jul 02 12:53PM

On Fri, 2 Jul 2021 13:52:53 +0300
>>> (I don't know whether there's a way to configure it to do so.)
 
>> Just out of interest, what byte order is the BOM in? Catch 22?
 
>This is probably a troll question, but answering anyway: the BOM marker
 
No, not a troll.
 
>U+FEFF is in the correct byte order, in both little-endian and
>big-endian UTF-16. That's how you tell them apart.
 
So its just 2 bytes in sequence, not a 16 bit value?
"Alf P. Steinbach" <alf.p.steinbach@gmail.com>: Jul 02 03:22PM +0200


>> U+FEFF is in the correct byte order, in both little-endian and
>> big-endian UTF-16. That's how you tell them apart.
 
> So its just 2 bytes in sequence, not a 16 bit value?
 
The BOM is a Unicode code point, U+FEFF as Paavo mentioned, originally
standing for an invisible zero-width hard space. It's encoded with
either little endian UTF-16 (then as two bytes), or as big endian UTF-16
(then as two bytes), or as endianness agnostic UTF-8 (then as three
bytes). The encoded BOM yields a reliable encoding indicator, though
pedantic people might argue that it's just statistical -- after all, one
just might happen to have a Windows 1252 encoded file with three
characters at the start with the same byte values as the UTF-8 BOM.
 
In the same vein, one just might happen to have a `.txt` file in Windows
with the letters "MZ" at the very start, like
 
MZ, Mishtara Zva'it, is the Military Police Corps of Israel. blah
 
and if you then try to open the file in your default text editor by just
typing the file name in old Cmd, those letters will be misinterpreted as
the initials of Mark Zbikowski, marking the file as an executable...
 
Since the chance of that happening isn't absolutely 0 one should never
use text file names as commands, or the UTF-8 BOM as an encoding marker.
 
 
- Alf
"Alf P. Steinbach" <alf.p.steinbach@gmail.com>: Jul 02 03:37PM +0200

On 2 Jul 2021 07:44, James Kuyper wrote:
> Windows, but can also be used on other platforms. If your code didn't
> need to be portable to other platforms, you could, by definition, rely
> upon Window's own guarantees about wchar_t.
 
I agree, but unfortunately both the C and C++ standards require
`wchar_t` to be able represent all code points in the largest supported
extended character set, and while that requirement worked nicely with
original Unicode, already in 1992 or thereabouts (not quite sure) it was
in conflict with extremely firmly established practice in Windows.
 
Bringing the standards in agreement with actual practice should be a
goal, but for C++ it's seldom done.
 
It /was/ done, in C++11, for the hopeless idealistic C++98 goal of clean
C++-ish `<c...>` headers that didn't pollute the global namespace. But
C++17 added stuff to only some `<c...>` headers and not to the
corresponding `<... .h>` headers, and that fact was then used quite
recently in a proposal to un-deprecate the .h headers but add all new
stuff only to `<c...>` headers. Which satisfies the politics but not the
in-practice of using code that uses C libraries designed as
C++-compatible, without running afoul of qualification issues.
 
And it /was/ done, in C++11, for both `throw` specifications and for the
`export` keyword, not to mention the C++11 optional conversion between
function pointers and `void*`, in order to support the reality of Posix.
 
But it seems to me, it's very very hard to get such changes through the
committee, just as individual people generally don't like to admit that
they've been wrong. Instead, C++20 started on a path of /introducing/
more conflicts with reality. In particular for `std::filesystem::path`,
where they threw the baby out with the bathwater for purely academic
idealism reasons.
 
- Alf
Paavo Helde <myfirstname@osa.pri.ee>: Jul 02 05:32PM +0300


>> U+FEFF is in the correct byte order, in both little-endian and
>> big-endian UTF-16. That's how you tell them apart.
 
> So its just 2 bytes in sequence, not a 16 bit value?
 
The file contains bytes, it's up to the reading code how to interpret
the bytes. It can interpret the bytes as uint16_t, i.e. cast the file
buffer as 'const uint16_t*' and read the first 2-byte value. If it is
0xFEFF, then it knows this is an UTF-16 file in a matching byte order.
If it is 0xFFFE, then it knows it's an UTF-16 file in an opposite byte
order, and the rest of the file needs to be byte-swapped.
 
It can also interpret the buffer as containing uint8_t bytes, but then
the logic is a bit more complex, it must then know if it itself is
running on a big-endian or little-endian machine, and behave accordingly.
James Kuyper <jameskuyper@alumni.caltech.edu>: Jul 02 04:15PM -0400

On 7/2/21 7:52 AM, Juha Nieminen wrote:
>> string literals and char16_t with code that needs to be portable to
>> Windows, but can also be used on other platforms.
 
> But doesn't that have the exact same problem as in my original post?
No, because the original post used wchar_t and the L prefix, for which
the relevant encoding is implementation-defined. That's not the case for
char and the u8 prefix, char16_t and the u prefix, or for char32_t and
the U prefix.
 
I have a feeling that there's a misunderstanding somewhere in this
conversation, but I'm not sure yet what it is.
 
 
> const char16_t *str = u"something";
 
> the stuff between the quotation marks in the source code will use
> whatever encoding (ostensibly but not assuredly UTF-8), which the
 
I don't understand why you think that the source code encoding matters.
The only thing that matters is what characters are encoded. As long as
those encodings are for the characters {'u', '""', '\\', 'x', 'C', '2',
'\\', 'x', 'A', '9', '"'}, any fully conforming implementation must give
you the standard defined behavior for u"\xC2\xA9".
 
> compiler needs to convert to UTF-16 at compile time for writing
> it to the output binary.
 
 
When using the u8 prefix, UTF-8 encoding is guaranteed, for which every
codepoint from U+0000 to U+007F is represented by a single character
with a numerical value matching the code point.
 
When using the u prefix, UTF-16 encoding is guaranteed, for which every
codepoint from U+0000 to U+D7FF, and from U+E000 to U+FFFF, is
represented by a single character with a numerical value matching the
codepoint.
 
When using the U prefix, UTF-32 encoding is guaranteed, for which every
codepoint from U+0000 to U+D7FF, and from U+E000 to U+10FFFF, is
represented by a single character with a numerical value matching the
codepoint.
 
Since the meanings of the octal and hexadecimal escape sequences are
defined in terms of the numerical values of the corresponding
characters, if you use any of those prefixes, specifying the value of a
character within the specified range by using an octal or hexadecimal
escape sequence is precisely as portable as using the UCN with the same
numerical value. Using UCNs would be better because they are less
restricted, working just as well with the L prefix and with no prefix.
However, within those ranges, octal and hexadecimal escapes will work
just as well.
 
Do you know of any implementation of C++ that claims to be fully
conforming, for which that is not the case? If so, how do they justify
that claim?
 
'\xC2' and '\xA9' are in the ranges for the u and U prefixes. They would
not be in the range for the u8 prefix, but since the context was wide
characters, the u8 prefix is not relevant.
 
 
> Or is it guaranteed that the characters between u" and " will
> always be interpreted as UTF-8?
 
Source code characters between the u" and the " will be interpreted
according to an implementation-defined character encoding. But so long
as they encode {'\\', 'x', 'C', '2', '\\', 'x', 'A', '9'}, you should
get the standard-defined behavior for u"\xC2\xA9".
Lynn McGuire <lynnmcguire5@gmail.com>: Jul 01 10:27PM -0500

On 6/10/2021 10:08 PM, Chris M. Thomasson wrote:
>> Has anyone read this and found it to be a good education on threads ?
 
>> https://www.amazon.com/C-Concurrency-Action-Anthony-Williams/dp/1617294691/
 
> I used to converse with Anthony way back. He knows his threads! :^)
 
I bought the book. It looks intense. Not a very big font either.
 
Lynn
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Jul 01 09:28PM -0700

On 7/1/2021 8:27 PM, Lynn McGuire wrote:
 
>>> https://www.amazon.com/C-Concurrency-Action-Anthony-Williams/dp/1617294691/
 
>> I used to converse with Anthony way back. He knows his threads! :^)
 
> I bought the book.  It looks intense.  Not a very big font either.
 
I have not seen his new book, but I am wondering if he mentions how to
use DWCAS in it with pure C++. I know he knows about it:
 
actually, read the whole thread where this message resides:
 
https://groups.google.com/g/lock-free/c/X3fuuXknQF0/m/Ho0H1iJgmrQJ
 
He calls it DCAS in that thread, buts DCAS and DWCAS are different
things. So, I am wondering if he mentions it in his 2nd edition.
red floyd <no.spam.here@its.invalid>: Jul 01 05:48PM -0700

On 7/1/2021 1:14 PM, Vir Campestris wrote:
> with is: This pointer from my database points to an interface. It might
> be a type 1 object, in which case do ONE(). It might be a type 2, in
> which case do TWO().
 
Why can't you use a virtual member function for this? Or is it to cast
the pointer from the database to one of two different hierarchies?
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

Thursday, July 1, 2021

Digest for comp.lang.c++@googlegroups.com - 20 updates in 2 topics

Vir Campestris <vir.campestris@invalid.invalid>: Jul 01 09:14PM +0100

On 28/06/2021 07:44, Bonita Montero wrote:
>> demon.
 
> dynamic_cast<> is slow and mostly the things you do with
> it could be done faster through a virtual function call.
 
Mostly.
 
I just did a line count on our codebase; we have about 1 dynamic cast
for every 10k lines. Compare with static_cast - 1 in 300.
 
(This is over several million lines of cpp files.)
 
I don't know what all the calls are, but the pattern I am most familiar
with is: This pointer from my database points to an interface. It might
be a type 1 object, in which case do ONE(). It might be a type 2, in
which case do TWO().
 
Andy
"Öö Tiib" <ootiib@hot.ee>: Jul 01 02:16PM -0700

On Thursday, 1 July 2021 at 23:14:24 UTC+3, Vir Campestris wrote:
> with is: This pointer from my database points to an interface. It might
> be a type 1 object, in which case do ONE(). It might be a type 2, in
> which case do TWO().
 
In some circumstances one can use typeid check and static_cast
or just dynamic_cast alone but making it with something else
will result with more code and likely be less efficient too.
Juha Nieminen <nospam@thanks.invalid>: Jul 01 04:42AM


> \x works in wide string literal too, and puts in a character with that
> value. The difference is that if the wide string type isn't unicode
> encoded then it might get the wrong character in the string.
 
The problem is that "\xC2\xA9" in UTF-8 is not the same thing as
"\xC2\xA9" in UTF-16 or UTF-32 (whichever wchar_t happens to be).
 
"\uXXXX", however, ought to work regardless because it specifies the
actual unicode codepoint you want, rather than its encoding.
Christian Gollwitzer <auriocus@gmx.de>: Jul 01 07:19AM +0200

Am 30.06.21 um 09:57 schrieb Juha Nieminen:
 
> const wchar_t* str = L"???";
 
> In the *source code* that string literal may be eg. UTF-8 encoded. However,
> the compiler needs to convert it to wide chars.
 
I think it is best to avoid wide strings. Now that doesn't help you if
you need them to call native Windows functions which insist on wchar_t.
 
I'm still wondering why you need to put a Unicode string in the source
code at all. Could you use an i18n feature of Windows to lookup the real
string? I'm not an expert of i18n on Windows, but using GNU gettext, you
would write some ASCII equivalent thing in the code and then have an
auxiliary translation file with a well defined encoding. At runtime the
ASCII string is merely a key into the table. Plus the added bonus that
you can support multiple languages.
 
Christian
Ralf Goertz <me@myprovider.invalid>: Jul 01 09:19AM +0200

Am Wed, 30 Jun 2021 12:37:55 +0200
> > are assumed to be utf16be.
 
> UTF-16-files have a byte-header which helps the compiler to
> distinguish ASCII-files and UTF-16-files.
 
I know that. It's called a byte order mark. And gcc ignores it.
David Brown <david.brown@hesbynett.no>: Jul 01 10:29AM +0200

On 01/07/2021 07:19, Christian Gollwitzer wrote:
> ASCII string is merely a key into the table. Plus the added bonus that
> you can support multiple languages.
 
>     Christian
 
Code can require non-ASCII characters without need internationalisation.
gettext and the like are certainly useful, but they are very heavy
tools compared to a fixed string or small table of strings in the code.
If you are writing a program for use in single company in Germany
(since you have a German email address), with all the texts in German,
would you want to use internationalisation frameworks just to make
"groß" turn out right?
 
The OP could also be working on embedded systems or some other code for
which having a single self-contained executable is important.
Juha Nieminen <nospam@thanks.invalid>: Jul 01 08:44AM

> (since you have a German email address), with all the texts in German,
> would you want to use internationalisation frameworks just to make
> "groß" turn out right?
 
There are also many situations where using non-ascii characters in
string literals may not be related to language and internationalization.
After all, Unicode contains loads of characters that are not related
to spoken languages, such as math symbols, and lots of other types
of symbols which are universal and don't require any sort of
internationalization. Sometimes these symbols may be used all on
their own, sometimes as part of text (eg. in labels and titles).
 
Also, unit tests for code supporting Unicode may benefit from
being able to use string literals with non-ascii characters.
(Of course, as noted in other posts in this thread, there is a
working solution to get around this, and it's the use of the \u
escape character.)
Kli-Kla-Klawitter <kliklaklawitter69@gmail.com>: Jul 01 11:10AM +0200

Am 01.07.2021 um 09:19 schrieb Ralf Goertz:
 
>> UTF-16-files have a byte-header which helps the compiler to
>> distinguish ASCII-files and UTF-16-files.
 
> I know that. It's called a byte order mark. And gcc ignores it.
 
No, wrong - gcc honors it since vesion 1.01.
Ralf Goertz <me@myprovider.invalid>: Jul 01 11:36AM +0200

Am Thu, 1 Jul 2021 11:10:55 +0200
> >> distinguish ASCII-files and UTF-16-files.
 
> > I know that. It's called a byte order mark. And gcc ignores it.
 
> No, wrong - gcc honors it since vesion 1.01.
 
I created this file b.cc:
 
int main() {
return 0;
}
 
using vi with
 
:set fileencoding=utf16
:set bomb
 
Then
 
~/c> file b.cc
b.cc: C source, Unicode text, UTF-16, big-endian text
 
or
 
~/c> od -h b.cc
0000000 fffe 6900 6e00 7400 2000 6d00 6100 6900
0000020 6e00 2800 2900 2000 7b00 0a00 2000 2000
0000040 2000 2000 7200 6500 7400 7500 7200 6e00
0000060 2000 3000 3b00 0a00 7d00 0a00
0000074
 
where you can see the BOM fffe. Feeding this to gcc (or g++) you get:
 
~/c> gcc b.cc
b.cc:1:1: error: stray '\376' in program
1 | �� i n t m a i n ( ) {
| ^
b.cc:1:2: error: stray '\377' in program
1 | �� i n t m a i n ( ) {
| ^
b.cc:1:3: warning: null character(s) ignored
1 | �� i n t m a i n ( ) {
| ^
b.cc:1:5: warning: null character(s) ignored
 
etc.
 
How does that qualify as "gcc honoring the BOM"?
David Brown <david.brown@hesbynett.no>: Jul 01 12:58PM +0200

On 01/07/2021 10:44, Juha Nieminen wrote:
>> "groß" turn out right?
 
> There are also many situations where using non-ascii characters in
> string literals may not be related to language and internationalization.
 
Good point.
 
> (Of course, as noted in other posts in this thread, there is a
> working solution to get around this, and it's the use of the \u
> escape character.)
 
Yes - but such workarounds are hideous compared to writing:
 
printf("Temperature %.1f °C\n", 123.4);
 
 
I am glad most of my code only has to compile with gcc, and I can ignore
such portability matters.
"Alf P. Steinbach" <alf.p.steinbach@gmail.com>: Jul 01 01:31PM +0200

On 30 Jun 2021 20:19, James Kuyper wrote:
> UTF-16 and UTF-32, respectively, making octal escapes redundant with and
> less convenient than the use of UCNs. But as he said, they do work for
> such strings.
 
You snipped some context, the example we're talking about.
 
That does decidedly not work in the sense of producing the intended string.
 
Perhaps I can make you understand this by talking about source code in
general. Yes, that example code is valid C++, so a conforming compiler
shall compile it with no errors; and yes, that code has a well defined
meaning, look, here's the C++ standard, it spells it out, what the
meaning is. But no, it doesn't do what you intended.
 
- Alf
Christian Gollwitzer <auriocus@gmx.de>: Jul 01 02:01PM +0200

Am 01.07.21 um 10:29 schrieb David Brown:
> (since you have a German email address), with all the texts in German,
> would you want to use internationalisation frameworks just to make
> "groß" turn out right?
 
I can see your point, but actually, most programs developed here in
Germany are still written in English. This is true for comments and
variable names etc., because there might be a non-German coworker
involved, and mostly because people are simply used to English as "the
computer language". I've seen German comments, variable names and
literal strings only at the university in introductory programming
courses etc. But admittedly, I never produced GUIs in C++, because there
are easier options available - and these usually come with good Unicode
support (e.g. Python). These smaller tools did not get i18n'ed.
I still think that if I had to make a program with a German interface,
it would make sense to write it with English strings and translate it
with a tool - because then, adding French or Turkish later on would be
easy.
 
 
> The OP could also be working on embedded systems or some other code for
> which having a single self-contained executable is important.
 
OK yes there are certainly points where this approach is not suitable.
Just wanted to bring another solution to the table.
 
Ceterum censeo wchar_t esse inutilem ;)
 
Christian
David Brown <david.brown@hesbynett.no>: Jul 01 02:57PM +0200

On 01/07/2021 14:01, Christian Gollwitzer wrote:
> computer language". I've seen German comments, variable names and
> literal strings only at the university in introductory programming
> courses etc.
 
Sure. The same is true here in Norway. But it is not true everywhere.
And even when you have English identifiers, comments, etc., the text
strings you show to users are often in a language other than English.
 
> But admittedly, I never produced GUIs in C++, because there
> are easier options available - and these usually come with good Unicode
> support (e.g. Python). These smaller tools did not get i18n'ed.
 
I do that too.
 
> it would make sense to write it with English strings and translate it
> with a tool - because then, adding French or Turkish later on would be
> easy.
 
Most software is written for one or a few customers, and one language
will always be sufficient. Of course, such software is also almost
always written for one compiler and one target, and portability of
source code is not an issue. This is particularly true if you have good
modularisation in the code - the user-facing parts with the text strings
are less likely to be re-used elsewhere than the more library-like code
underneath.
 
 
> OK yes there are certainly points where this approach is not suitable.
> Just wanted to bring another solution to the table.
 
> Ceterum censeo wchar_t esse inutilem ;)
 
Agreed - and salt the ground it was built on, to save future generations
from its curse!
Manfred <noname@add.invalid>: Jul 01 03:44PM +0200

On 7/1/2021 7:19 AM, Christian Gollwitzer wrote:
> auxiliary translation file with a well defined encoding. At runtime the
> ASCII string is merely a key into the table. Plus the added bonus that
> you can support multiple languages.
 
In Windows programming the need for wchar_t strings is relatively
common, since this its native character set. Most APIs are provided with
both ASCII and WCHAR variants, however if you need more-than-plain-ascii
text support you almost invariably end up #define'ing UNICODE and thus
default to the wide char variants - moreover some APIs are given for
WCHAR strings only.
In these cases if you need strings literals they are best expressed as
WCHAR strings directly to avoid unnecessary conversions at runtime.
 
 
Kli-Kla-Klawitter <kliklaklawitter69@gmail.com>: Jul 01 04:17PM +0200

Am 01.07.2021 um 11:36 schrieb Ralf Goertz:
> b.cc:1:5: warning: null character(s) ignored
 
> etc.
 
> How does that qualify as "gcc honoring the BOM"?
 
Use v1.01.
James Kuyper <jameskuyper@alumni.caltech.edu>: Jul 01 10:58AM -0400

On 7/1/21 12:42 AM, Juha Nieminen wrote:
>> encoded then it might get the wrong character in the string.
 
> The problem is that "\xC2\xA9" in UTF-8 is not the same thing as
> "\xC2\xA9" in UTF-16 or UTF-32 (whichever wchar_t happens to be).
 
Why would you use wchar_t if you char about unicode? You should be using
string literal using either the u8, u, or U prefixes, and store/access
the strings as arrays of char, char16_t, or char32_t, respectively. Such
literals are guaranteed to be in UTF-8, UTF-16, or UTF-32 encoding,
respectively.
Keith Thompson <Keith.S.Thompson+u@gmail.com>: Jul 01 10:13AM -0700

> Am 01.07.2021 um 11:36 schrieb Ralf Goertz:
>> Am Thu, 1 Jul 2021 11:10:55 +0200
>> schrieb Kli-Kla-Klawitter <kliklaklawitter69@gmail.com>:
[...]
>>>> I know that. It's called a byte order mark. And gcc ignores it.
 
>>> No, wrong - gcc honors it since vesion 1.01.
>> I created this file b.cc:
[...]
>> How does that qualify as "gcc honoring the BOM"?
 
> Use v1.01.
 
You think you're funny. You're not.
 
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */
Kli-Kla-Klawitter <kliklaklawitter69@gmail.com>: Jul 01 07:27PM +0200

Am 01.07.2021 um 19:13 schrieb Keith Thompson:
>>> How does that qualify as "gcc honoring the BOM"?
 
>> Use v1.01.
 
> You think you're funny. You're not.
 
v1.01 does honor the BOM.
Keith Thompson <Keith.S.Thompson+u@gmail.com>: Jul 01 11:21AM -0700


>>> Use v1.01.
>> You think you're funny. You're not.
 
> v1.01 does honor the BOM.
 
At the risk of giving the impression I'm taking you seriously, the
oldest version of gcc available from gnu.org is 1.42, released in 1992.
 
I've see no evidence that gcc v1.01 would have honored the BOM, but it
doesn't matter, since that version is obsolete and unavailable.
 
I conclude that you are a troll.
 
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */
Real Troll <real.troll@trolls.com>: Jul 01 06:45PM

On 01/07/2021 19:21, Keith Thompson wrote:
 
> I conclude that you are a troll.
 
It takes one troll to know another. This is an expert opinion of a Real Troll!
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.