Saturday, July 3, 2021

Digest for comp.lang.c++@googlegroups.com - 11 updates in 4 topics

rob <rob@drrob.com>: Jul 03 04:12PM -0400

This is my test program
 
#include everything relevant here
int main {
int a = 0;
float b = 1.0;
char c = 'c';
 
int *ptrA;
float *ptrB;
char *ptrC;
 
ptrA = &a;
ptrB = &b;
ptrC = &c;
 
cout << "value of a: " << a << "; address of a: " << ptrA << endl;
cout << "vaue of b: " << b << "; address of b: " << ptrB << endl;
cout << "value of c: " << c << "; address of c: " << ptrC << endl;
 
return 0;
}
 
 
This program, compiled w/ gcc 9.3 on Pop_OS 20.04, does not print an
address for c. It just prints "c"; this does show addresses for a and
b.
 
Why can't I show the address for the char variable c?
 
Thx,
Rob
Ben Bacarisse <ben.usenet@bsb.me.uk>: Jul 03 09:27PM +0100


> This is my test program
 
> #include everything relevant here
> int main {
 
And you need ()s there and at least a "using namespace std;" unless you
are using a museum version of C++.
 
 
> cout << "value of a: " << a << "; address of a: " << ptrA << endl;
> cout << "vaue of b: " << b << "; address of b: " << ptrB << endl;
> cout << "value of c: " << c << "; address of c: " << ptrC << endl;
 
What would you like this code to do:
 
char *string = "Hello world\n";
cout << string;
 
? Can you see the problem now?
 
> address for c. It just prints "c"; this does show addresses for a and
> b.
 
> Why can't I show the address for the char variable c?
 
You can if you do this:
 
cout << "value of c: " << c << "; address of c: " << (void *)ptrC << endl;
 
--
Ben.
rob <rob@drrob.com>: Jul 03 05:54PM -0400

Thanks, that helps me.
 
 
 
 
Real Troll <real.troll@trolls.com>: Jul 03 10:04PM

On 03/07/2021 22:54, rob wrote:
 
>>> Why can't I show the address for the char variable c?
>> You can if you do this:
 
>> cout << "value of c: " << c << "; address of c: " << (void *)ptrC << endl;
 
You could also do something like this:
 
Richard Damon <Richard@Damon-Family.org>: Jul 03 02:06PM -0400

On 7/3/21 1:06 PM, Juha Nieminen wrote:
> 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).
 
Add the solution for the readability is to just write the code as native
literals, but NOT as the actual C++ file, and have a filter stage that
translates this file into the actual C++ code with the escapes.
 
The language was designed for this sort of functionality.
James Kuyper <jameskuyper@alumni.caltech.edu>: Jul 03 05:49PM -0400

On 7/3/21 12:59 PM, Juha Nieminen wrote:
 
> 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.
 
That sequence specifies a character with a value of 0xC2 followed by a
character with a value of 0xA9. When the characters in question are
wider than 8 bits, that is NOT the UTF-8 encoding of the character you
want. Which just means you need to specify the right character.
 
 
> 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. ...
 
That's because you didn't specify what you wanted. You should have used
\u00A9 rather than \xC2\xA9.
 
> ... 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.
 
You got precisely what you specified - if it's not what you wanted, you
need to change your specification.
Richard Damon <Richard@Damon-Family.org>: Jul 03 01:59PM -0400

On 7/3/21 12:04 PM, Bonita Montero wrote:
>> 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.
 
Doesn't handle the Animal -> Mammel -> Canine -> Dog -> Poodle case
without a big lookup table to say that Poodles are also Dogs and
Canines, and Mammels.
 
You STILL need to edit the Animal.h file every time you add new derived
class. Lack of Encapsulation.
Richard Damon <Richard@Damon-Family.org>: Jul 03 02:03PM -0400

On 7/3/21 12:04 PM, Bonita Montero wrote:
>> 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.
 
And why add a function like that when you could just use typeid(). You
still need the table to handle types that might be sub-classed.
dynamic_cast provides all that capability as built in functionality.
Mr Flibble <flibble@reddwarf.jmc>: Jul 03 08:06PM +0100

On Sat, 3 Jul 2021 13:59:14 -0400
> Canines, and Mammels.
 
> You STILL need to edit the Animal.h file every time you add new
> derived class. Lack of Encapsulation.
 
You are both wrong; if you are using dynamic_casts or isDog() then that
suggests you animal abstraction isn't elaborate enough, animal class
should include a list of behaviours as child objects (i.e. composition
instead of inheritance) and one such behaviour might be barking,
canBark(), and could be used together with the visitor pattern, for
example.
 
/Flibble
Siri Cruise <chine.bleu@yahoo.com>: Jul 03 11:01AM -0700

In article <hKudnUFx1oVw4n39nZ2dnUU7-aPNnZ2d@giganews.com>,
 
> Conclusion(3) From the above true premises it necessarily follows that
> simulating halt decider H correctly reports that its input: (P,P) never
> halts.
 
Number theory conjectures can be written as Turing Machines to
produce a counterexample that halt on a counterexample or do not
halt if the conjecture is true. Assume the halting problem is
decidable, then the conjecture can be decided. But this
contradicts Goedel that number theory has undecidable statements.
Therefore the halting problem is undecidable.
 
p is prime: P = \p, k. [
k*k>p -> true;
k*k<=p and p mod k = 0 -> false;
k*k<=p and p mod k /= 0 -> P(p, k+1)
]
 
goldbach conjecture counterexample: E = \n, i, j. [
~P(i, 2) and i<n and j<n -> E(n, i+1, j);
~P(j, 2) and i<n and j<n -> E(n, 2, j+1);
i>=n and j<n -> E(n, 2, j+1);
i>=n and j>=n -> n;
P(i, 2) and P(j, 2) and i<n and j<n and i+j=n -> E(n+2, 2, 2);
P(i, 2) and P(j, 2) and i<n and j<n and i+j/=n -> E(n, i+1, j)
]
 
goldbach conjecture: G = \.E(4, 2, 2)
 
Prove G halts.
 
 
ob-langc
 
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
 
typedef long long unsigned Integer;
 
static bool P (Integer p) {
Integer k = 2;
for (; k*k<=p; ++k) if (p%k==0) return false;
return true;
}
 
static void G (void) {
Integer n = 4, i = 2, j = 2;
for (; ;)
if (i>=n && j>=n) {
printf("%llu counterexample\n", n);
return;
}else if (i>=n) i = 2, ++j;
else if (!P(i)) ++i;
else if (!P(j)) i = 2, ++j;
else if (i+j!=n) ++i;
else {
printf("%llu = %llu+%llu\n", n, i, j);
n += 2; i = j = 2;
}
}
 
int main (int argc, char **argv) {
G(); return 0;
}
 
--
:-<> Siri Seal of Disavowal #000-001. Disavowed. Denied. Deleted. @
'I desire mercy, not sacrifice.' /|\
Discordia: not just a religion but also a parody. This post / \
I am an Andrea Doria sockpuppet. insults Islam. Mohammed
olcott <NoOne@NoWhere.com>: Jul 03 01:15PM -0500

On 7/3/2021 1:01 PM, Siri Cruise wrote:
 
> int main (int argc, char **argv) {
> G(); return 0;
> }
 
The Goldbach conjecture is not undecidable in the conventional sense in
that we know that both {Yes and No} are the wrong answer. The Goldbach
conjecture is undecided and not undecidable.
 
--
Copyright 2021 Pete Olcott
 
"Great spirits have always encountered violent opposition from mediocre
minds." Einstein
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.

No comments: