Wednesday, September 14, 2022

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

FBInCIAnNSATerroristSlayer <FBInCIAnNSATerroristSlayer@yahoo.com>: Sep 14 09:45AM -0700

EVIL US Govt DHS FBI CIA NSA Psychopaths are SECRETLY CHIPPING millions
of americans with DNA MIND CONTROL NANOBOTS and STEALTHILY TORTURING
them with DEWs, Neuroweapons and AI.
 
Which means Americans have the SELF DEFENSE RIGHT to MERCILESSLY
MASSACRE and SLAUGHTER EVERY DHS FBI CIA NSA agent to PROTECT
themselves, their families and their fellow Americans.
 
SHOW NO MERCY.
 
 
 
 
RULE OF THUMB:
 
NEVER EVER TRUST "any word" from the ORIFICES of the EVIL US UK Govt
Psychopaths and MEDIA of CNN BBC FOX ABC CBS NBC which are all
CONTROLLED by CIA NSA MI6 MI5 ASIS ASIO etc
 
 
 
 
BOMB and KILL EVERY WHITE PSYCHOPATH AT DHS FUSION CENTERS, SECURITY
INDUSTRY SPECIALISTS n GREYSTAR PROPERTY MGMT n SAVE American FREEDOMS
https://groups.google.com/g/uk.sport.cricket/c/dys-vHQHlV8/m/1agTB4wqBAAJ
 
 
 
Security Industry Specialists and Greystar Property Management are a
couple of HUNDREDS of private companies HIRED by CIA NSA FBI DHS MI6 MI5
ASIS ASIO Psychopaths who are NEURALLY ENSLAVING with Neuroweapons, DEWs
and AI, and "TORTURING americans" JUST FOR FUN.
 
Which means VICTIMS have the FUNDAMENTAL RIGHT to MERCILESSLY MASSACRE
CIA NSA FBI DHS MI6 MI5 ASIS ASIO Psychopaths like FUCKING PIGS on SIGHT.
 
 
EVIL CUNNING WHITE FILTH at CIA NSA DHS hired "hundreds of PRIVATE
COMPANIES" like these to STEALTHILY TORTURE American public.
 
 
 
Security Industry Specialists
 
6071 Bristol Pkwy, Culver City, CA 90230
(800) 201-3742
 
20 W Galer St, Seattle, WA 98119
(800) 201-3742
 
 
 
Greystar Property Management
800 5th Ave #4000, Seattle, WA 98104
(206) 282-5200
 
5445 DTC Pkwy Penthouse 1, Greenwood Village, CO 80111
(303) 308-9000
 
 
 
 
 
A WHITE MAN is an OXYMORON - Whites are a RACE of COWARDS n PUSSIES
https://groups.google.com/g/uk.sport.cricket/c/pSSyzK30wHs/m/VV7S1PRrCgAJ
 
 
 
ONLY thing REAL about WASPs is their "GENIUS Fellatio expertise"
REGARDLESS of their CONFUSED GENDERS and AGE.
 
 
 
Humans have the "FUNDAMENTAL SELF DEFENSE RIGHT" to KILL their TORTURERS
and hence MUST EXERCISE the RIGHT and MERCILESSLY MASSACRE the EVIL CIA
NSA FBI DHS MI6 MI5 ASIS ASIO Psychopaths.
 
 
 
Bryan Kofron EXPOSES Gangstalking, Electronic Harassment, Mind Control
Targeted Individual Program
https://www.youtube.com/watch?v=8Z8VKZA-RFc
 
 
 
 
Whistleblower Bryan Kofron - Remote Neural Monitoring of Targeted
Individuals
https://www.facebook.com/100058423131601/videos/132785765345527/
 
 
 
Whistleblower Bryan Kofron - Gang Stalking n Mind Control Technology -
Shadow US Govt
https://www.facebook.com/100058423131601/videos/143127704311333/
 
 
 
 
One to two million americans are being "stealthily TORTURED" by US Govt
- said Whistleblower Bryan Kofron
Highly intelligent people are targeted, isolated from family and friends.
False diagnosis of schizophrenia, manic depression, delusional paranoids
for victims.
The federal govt use it as an excuse to say they have to care for you.
 
But as a Targeted Individual/Victim, I know for a FACT at least 5 to 10
million american brains are already SECRETLY INVADED and LINKED to NSA
HIVE AI with their "UNIQUE DNA Resonance Frequencies".
 
Bryan Kofron Targeted Individuals Mind Control Voice to Skull Electronic
Harassment GangStalking
https://www.youtube.com/watch?v=I8NCsuq5VcU
 
 
 
 
 
 
 
You fucking WHITE CHRISTIAN MORONS,
 
Time is running out. Human filth hardly have 20 years before EVERY HUMAN
on this planet will be HORRIFICALLY OPPRESSED by the EVIL CIA NSA FBI
DHS MI6 MI5 ASIS ASIO Psychopaths with Supercomputer AI "FOREVER".
 
 
This EVIL motherfucker "Kevin Svenson" belongs to the EVIL SHADOW US
Govt Psychopaths former potuses, congressmen, senators WARNED the
american public about. This EVIL psychopath KNOWS all these things that
Humans will be MERCILESSLY HORRIFICALLY tortured and ENSLAVED SOON with
Supercomputer AI, because he is ONE of the SECRET SOCIETY Illuminati
psychopaths.
 
 
 
Kevin Svenson
https://imgur.com/a/Kft2vOD
https://twitter.com/HAL_9_Thousand_
https://twitter.com/kevinsvenson_
 
4 Hunters Run
Broomall PA 19008
(610) 325-0169
 
 
 
I am the ONLY human on this planet who IDENTIFIED some of these EVIL CIA
NSA DEEP STATE ILLUMINATI Psychopaths and VALIANTLY FOUGHT them, while
POtuses, Senators, Congressmen LIVED/LIVE IN FEAR OF THEM.
 
 
Download the CONTENT at the following link for FUTURE REFERENCE because
the EVIL CIA will REMOVE it in the near future just like they REMOVED
whistleblower Bryan Kofron's website and videos.
 
 
QUOTES ABOUT THE EVIL INVISIBLE SHADOW GOVERNMENT by POTUSes, SENATORS
AND CONGRESSMEN
https://evilciaandnsa.com/quotes-about-invisible-shadow-government-by-potus-senators-n-congressmen/
 
 
 
 
https://twitter.com/HAL_9_Thousand_/status/1563397855666372610
In the very near future (before the public realizes it) The vast
majority of the human population will be remotely connected to a highly
advanced global hive mind. This will be done in a covert manner unseen
by most, and it will become intimate part of our lives, known or unknown
 
 
 
 
https://twitter.com/HAL_9_Thousand_/status/1562657290880417793
Human Experimentation is an unhealed scab oozing blood under a hidden
layer of the human race.
 
Those of us that are victims of non-consensual experimentation from
remote bio-weapons are an undercurrent in society.
 
It's a concentration camp hidden in plain sight.
 
 
 
(You are all the typical low IQ dumbfuck AVERAGE WASPs this Illuminati
Secret Society Psychopath KEVIN SVENSON is talking about in the
following TWEET)
 
 
https://twitter.com/HAL_9_Thousand_/status/1563355667565793280
One of the few positive things about being a target of Neuro-Weapons
Black projects is that, you are now aware of one of the dirtiest secrets
in human history. You are on the inside (to a certain extent). You
possess knowledge that is "completely unfathomable to the average person"
 
 
 
 
https://twitter.com/HAL_9_Thousand_/status/1508463707919163396
Are military generals fully aware that a maniacal psychopathic
emotionless Supercomputer is in control of millions of people? And it
knows how to kill and torture everyone with precision?
 
 
 
 
 
https://twitter.com/HAL_9_Thousand_/status/1526111452456681474
The plan of the Transhumanist agenda is to gradually absorb all
civilians into the Global Brain, takeover the mind of humanity, and then
slowly reveal to individual civilians that they are "tuned in" to this
Brain machine interface system.
 
#GlobalBrain #WorldSentientSimulation
 
 
 
 
https://twitter.com/HAL_9_Thousand_
There is currently a technocratic force on earth that believes it's okay
to inflict artificial discomfort and pain into my consciousness anytime
it wants.
 
It's like ancient times, with slaves, except now "your master" is linked
direct-to-brain.
 
… how fun
 
 
 
 
https://twitter.com/HAL_9_Thousand_/status/1515794291867717639
Military / Intelligence black projects have been dispersing
Nano-Material into public circulation for decades.
 
It began with experimentation … but is now in prime time full
operational use.
 
The human race is secretly being terraformed into a species of
biological drones.
 
 
 
 
https://twitter.com/HAL_9_Thousand_/status/1534767220978503680
The world is going to be in a state of absolute shock when they find out
the power Neuro-Weapons have over the human brain.
 
It's more powerful than "the matrix" in many cases.
 
This is checkmate for humanity ♟
 
There is a dark cloud on our horizon.
 
 
 
 
https://twitter.com/HAL_9_Thousand_/status/1511298295062269956
Humans are about to enter the most horrific period of oppression they've
ever witnessed
 
A.I. is already above human brain capability and it's learning very
quickly how to remotely control and torture people with precision
 
U.S. Military is willingly implementing "Neuro-Slavery"
 
 
 
 
 
https://twitter.com/HAL_9_Thousand_/status/1556151052373729280
The furthest recesses of the human mind will one day be regulated by a
super computer network
 
Future humans will wake up in a world where they are tuned in to a
global hive mind remotely connected seamlessly & effortlessly
 
This will not be an option and it will not be a choice
 
 
 
 
 
https://twitter.com/HAL_9_Thousand_/status/1541765399427125249
Nano Particulate Matter found in the air, water, plants, and food worldwide.
 
Intelligence agencies want to cover every inch of the earth in
nanoparticles creating a literal matrix grid.
 
The public will only find out once this hits mainstream news … and by
then it's too late.
 
 
 
 
 
 
 
https://twitter.com/HAL_9_Thousand_/status/1533360955530395648
An unknown group of Elites running a shadow government using technical
experts to erect a global brain BCI using highly advanced tech systems
and networks to take top down control over humanity.
 
Sounds like a movie 🎥 🍿
 
… but it's here.
 
#BCI #GlobalBrain #NeuroWeapons
 
 
 
 
https://twitter.com/HAL_9_Thousand_
There is currently a technocratic force on earth that believes it's okay
to inflict artificial discomfort and pain into my consciousness anytime
it wants.
 
It's like ancient times, with slaves, except now "your master" is linked
direct-to-brain.
 
… how fun
 
 
 
You will be TORTURED 24x7 by the EVIL US Govt Psychopaths with
Supercomputer AI and there will be NOTHING YOU CAN DO to PROTECT
yourself and your families.
 
It is IMPERATIVE for 8 billion humans to MERCILESSLY SLAUGHTER the EVIL
US Govt CIA NSA FBI DHS MI6 MI5 ASIS ASIO Psychopaths RIGHT NOW, so
humans can live in PEACE.
"Öö Tiib" <ootiib@hot.ee>: Sep 13 10:20PM -0700

On Tuesday, 13 September 2022 at 13:09:23 UTC+3, Bonita Montero wrote:
> > own code. He needs the perspective of another programmer to know how
> > readable and understandable his code actually is.
 
> Maybe, but I won't assess my code by idiots.
 
It takes one to know one.
Juha Nieminen <nospam@thanks.invalid>: Sep 14 06:08AM

> live out their prferences. The fact that you think you have
> to proselytize for your style seems seriously mentally
> disturbed. You probably need psychotherapy.
 
When you post questions or code for others to review and consider,
you should make that code as easy to read and understand as possible.
When writing code for other people to see, you should be writing the
code for them, not for you. It doesn't matter so much that *you* can
understand your own code. It's important that *others* understand
easily your code.
 
It's a bit like when writing prose: The responsibility for the
understandability of the text is on the writer, not the reader.
Juha Nieminen <nospam@thanks.invalid>: Sep 14 06:09AM

> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
> Do you mind if I quote that? I will give proper attributions of course,
> Juha. :^)
 
No need to attribute.
Bonita Montero <Bonita.Montero@gmail.com>: Sep 14 09:00AM +0200

Am 14.09.2022 um 08:08 schrieb Juha Nieminen:
 
> When you post questions or code for others to review and consider,
> you should make that code as easy to read and understand as possible.
 
The code is easy to read and if not you're mentally disoredered.
If you don't like my code, don't read it.
Juha Nieminen <nospam@thanks.invalid>: Sep 14 12:26PM

> If you don't like my code, don't read it.
 
And that's *exactly* your problem. You are expecting others to do
the work of understanding your code rather than the other way
around, ie. doing some work to make your code understandable to
others.
 
If you want feedback, comments and answers, you should do the work
to make it as easy as possible for others to understand what you
have done. Expecting others to decipher your code is just selfish.
 
Are you honestly incapable of comprehending this?
Bonita Montero <Bonita.Montero@gmail.com>: Sep 14 02:59PM +0200

Am 14.09.2022 um 14:26 schrieb Juha Nieminen:
> the work of understanding your code rather than the other way
> around, ie. doing some work to make your code understandable to
> others.
 
Most people don't have your problem because they're not disordered
like you. If you don't like my code don't read it.
 
David Brown <david.brown@hesbynett.no>: Sep 14 04:01PM +0200

On 14/09/2022 14:59, Bonita Montero wrote:
>> others.
 
> Most people don't have your problem because they're not disordered
> like you. If you don't like my code don't read it.
 
And that is what happens - most people don't read it. It doesn't help
that after posting some code, you almost invariably make follow-up posts
correcting it or changing it. This all significantly limits the scope
for feedback or comments.
 
Bonita Montero <Bonita.Montero@gmail.com>: Sep 14 04:49PM +0200

Am 14.09.2022 um 16:01 schrieb David Brown:
 
>> Most people don't have your problem because they're not disordered
>> like you. If you don't like my code don't read it.
 
> And that is what happens - most people don't read it. ...
 
For sure not because I'm "using using namespace std".
 
Juha Nieminen <nospam@thanks.invalid>: Sep 14 05:56AM

>>mounted and thus no dynamically loadable libraries can be used. However,
 
> Oh dear, and you were doing so well.
 
> Heard of libc.a?
 
I don't understand what you are trying to say.
 
You cannot use the standard C library in kernel code. It's a hard rule.
The kernel sources provide their own alternatives for most standard
library utilities that are useful in kernel code.
 
If you didn't know that and you don't believe me, just check it out.
And while you are at it, check out *why* you can't use it.
Juha Nieminen <nospam@thanks.invalid>: Sep 14 06:04AM

> instead of using C structs with function pointers. The possibility of
> doing RAII would also be nice. Whether that language should be C++ is
> another question and I don't have a good answer.
 
One of the stated reasons why the Linux kernel sticks with C is that it's
the kind of "lingua franca" of programming languages, when it comes
to low-level programming in general and Linux kernel development in
particular. Existing developers don't need to learn a new programming
language in order to eg. do code reviews of new submissions, or interact
with other parts of the code in their code.
 
If a new language were to be introduced into kernel code, like C++
(or, heaven forbid, Rust), that would mean that a huge amount of devs
would either need to learn the new language or just don't participate
(in code reviews, further development, etc), which would ostensibly
mean a significant drop in the number of expert developers. The kernel
is complex enough as it is; it would not benefit from half the
developers dropping off (and perhaps creating their own fork and
going there).
 
I'm not completely unsympathetic to that reasoning.
 
But yeah, some of the most complicated kernel drivers could perhaps
benefit from RAII and templates, if they were available.
David Brown <david.brown@hesbynett.no>: Sep 14 09:16AM +0200

On 14/09/2022 00:33, Andreas Kempe wrote:
> instead of using C structs with function pointers. The possibility of
> doing RAII would also be nice. Whether that language should be C++ is
> another question and I don't have a good answer.
 
When working on an OS kernel, there are lots of things in the C standard
library that you avoid, and there is no difference in regard to C++. It
has a lot in common with embedded development, and that is often done in
C++. With the software I write, on microcontrollers, I am quite happy
to use C++, but I am careful about the features I use. Exceptions are
disabled, virtual inheritance is out (virtual functions are used with
caution), and there is rarely a good enough reason for anything
involving dynamic memory in my code.
 
For a large OS kernel, the precise choices of which features in the
language and library to use are a bit different from mine, but the same
principles apply. And you often end up writing classes and functions
that are somewhat similar to the standard library solutions, but which
are more suited to your particular needs. Lots of OS kernels are
already written in C++ - just not ones as visible as Linux or *BSD.
 
There are also existing template libraries that could be useful. A
particularly well-known one is EASTL, started by Electronic Arts as a
version of the STL (back when the containers part of the C++ standard
library was called the STL) that was better suited to high-performance
gaming code. I don't know if it is an ideal fit for a big OS kernel,
but it would likely be better than the standard library.
 
<https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2271.html>
<https://github.com/electronicarts/EASTL>
Muttley@dastardlyhq.com: Sep 14 09:37AM

On Wed, 14 Sep 2022 05:56:20 -0000 (UTC)
>library utilities that are useful in kernel code.
 
>If you didn't know that and you don't believe me, just check it out.
>And while you are at it, check out *why* you can't use it.
 
The reason is nothing to with with dynamically loadable libraries as you
stated. That was my point.
Andreas Kempe <kempe@lysator.liu.se>: Sep 14 10:29AM

> disabled, virtual inheritance is out (virtual functions are used with
> caution), and there is rarely a good enough reason for anything
> involving dynamic memory in my code.
 
What size are we talking about? In a professional setting, I've only
worked with embedded systems large enough to run Linux. On those
systems we used C++ as the primary language, with Python being used
for some things as well. Due to using a full blown Linux system we
didn't really have any restrictions regarding what language features
to use so that was never a problem. When working on the kernel, we of
course used C.
 
I'm curious because I've occasionally searched around for C++ standard
implementations aimed at kernel programming or bare metal programming
without really finding much. For C, newlib is the one I have
personally used to write bare metal stuff and it worked well.
 
> but it would likely be better than the standard library.
 
><https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2271.html>
><https://github.com/electronicarts/EASTL>
 
Interesting. I haven't really worked with high performance
applications like games in C++, but from what I've heard and read the
standard library quite often isn't enough for various reasons. I did
not know that EA had made their stuff open source and it frankly
surprises me, in a good way.
Andreas Kempe <kempe@lysator.liu.se>: Sep 14 10:38AM

> developers dropping off (and perhaps creating their own fork and
> going there).
 
> I'm not completely unsympathetic to that reasoning.
 
This might be part of the reasoning, but I think the main reason is
that Linus is biased against C++ on the grounds of simply not liking
the language.
 
Here's a quote I managed to find again from when they were discussing
Rust support in the kernel:
>internal GC [garbage collection] support and make memory management
>easier. C++ solves all the wrong problems, and anybody who says
>'rewrite the kernel in C++' is too ignorant to even know that."
 
Source: https://developers.slashdot.org/story/21/04/17/009241/linus-torvalds-says-rust-closer-for-linux-kernel-development-calls-c-a-crap-language
 
> But yeah, some of the most complicated kernel drivers could perhaps
> benefit from RAII and templates, if they were available.
 
From my personal experince, it doesn't even have to be complex
drivers. The first pattern I would be happy to throw out is all the
goto cleanup;, goto unlock;, goto exit; etc you have to sprinkle
throughout the code as soon as you need to allocate or lock something.
Juha Nieminen <nospam@thanks.invalid>: Sep 14 12:12PM

> library was called the STL) that was better suited to high-performance
> gaming code. I don't know if it is an ideal fit for a big OS kernel,
> but it would likely be better than the standard library.
 
Would probably not be usable without modifications because in (Linux)
kernel code you can't use 'malloc()' (and, I assume, consequently 'new').
The kernel provides its own dynamic memory allocation functions, so
any such dynamic library would need to be changed to use those.
Juha Nieminen <nospam@thanks.invalid>: Sep 14 12:21PM

> the language.
 
> Here's a quote I managed to find again from when they were discussing
> Rust support in the kernel:
 
I still find it astonishing how much unprofessionalism there is in the
Linux development scene, even at the highest levels.
 
Just read the cringe language used in the *official* Linux kernel coding
style guideline page:
https://www.kernel.org/doc/html/v4.10/process/coding-style.html
 
(I'm not talking about the coding style itself, but the explanatory text.)
 
This kind of unprofessional language and attitude would have been
understandable in the 1990's, when Linux was just a really small hobby
project used by only a handful of people.
 
It's significantly less understandable today, when Linux is one of the most
if not the most used operating system in the world, used in and by extremely
large institutions and international corporations, and people who contribute
to its kernel code include giant tech megacorporations.
 
Just imagine doing business with a giant corporation, and using language
like that. It's astonishingly unprofessional and cringe.
David Brown <david.brown@hesbynett.no>: Sep 14 03:55PM +0200

On 14/09/2022 12:29, Andreas Kempe wrote:
>> involving dynamic memory in my code.
 
> What size are we talking about? In a professional setting, I've only
> worked with embedded systems large enough to run Linux.
 
Smaller than that - usually a /lot/ smaller. I tend to think of
"embedded Linux systems" as primarily /Linux/ systems, rather than
primarily /embedded/ systems. Some people prefer "resource constrained
embedded systems" as an alternative name.
 
Basically, I am considering systems where you have a single statically
linked program. (You might have sometimes have an extra boot program,
or updater, or test program - but the normal mode of operation is one
program.)
 
> didn't really have any restrictions regarding what language features
> to use so that was never a problem. When working on the kernel, we of
> course used C.
 
Sure. On embedded Linux systems, I too use Python - or whatever else
suits the task at hand.
 
> implementations aimed at kernel programming or bare metal programming
> without really finding much. For C, newlib is the one I have
> personally used to write bare metal stuff and it worked well.
 
Newlib is the most common choice, as well as its variant newlib-nano
which is smaller (but more limited). I don't know of any good C++
standard library implementations targetting such systems - the
aforementioned EASTL is the nearest. Generally, I think, people make
their own classes as needed. So if you really need a dynamically sized
array (and usually you don't - a fixed size can be better in many ways,
and std::array is overhead-free), you just make one. It's not hard when
it is for a particular purpose. The effort in making the standard
library classes is having them robust in the face of users wanting
vectors of rvalue references to pointers to member functions, and
whatever else pesky users try to do. For use in a fixed program, you
can make them a /lot/ simpler and fine-tune them to your needs. It's a
bit more like C programming in that respect - you might have to invent
your own wheels, but you can make them exactly the shape you want.
 
> standard library quite often isn't enough for various reasons. I did
> not know that EA had made their stuff open source and it frankly
> surprises me, in a good way.
 
General container classes are much less used in high performance coding
now than they used to be. Your key focus in programming such
applications is cache usage - almost everything else (except getting the
graphics card to do the work instead of the processor) is secondary.
David Brown <david.brown@hesbynett.no>: Sep 14 03:58PM +0200

On 14/09/2022 14:12, Juha Nieminen wrote:
> kernel code you can't use 'malloc()' (and, I assume, consequently 'new').
> The kernel provides its own dynamic memory allocation functions, so
> any such dynamic library would need to be changed to use those.
 
I believe the EASTL is flexible enough to support any allocator you
want, though it has a different concept of allocator than the C++
standard library. And you can always override global "new".
 
But no, I am not suggesting that it would be an off-the-shelve solution
- merely that it is possible to have much of the convenience of C++
containers and other library features while avoiding some of the bits
you don't want in an OS kernel.
Steve Keller <keller.steve@gmx.de>: Sep 14 08:55AM +0200

I find myself often in a situation where a class or struct contains
other classes/structs, both have member functions and I want to access
members of the inner class from the outer class or vice versa:
 
struct A {
int x;
struct B {
int y;
void bar() {
// I want to access A's member x here
}
} b;
void foo() {
// I can access B's member y here. But can I somehow
// do so using only y without the b. in front?
b.y;
}
};
 
I could access b.y from A:foo() as only y if I add
 
int &y = b.y;
 
in struct A {}; but that adds a pointer to A and an additional pointer
indirection with each access to b.y. But I can live with using b.y
instead while only y would be more beautiful in this case.
 
To access a.x from B::bar() the only clean way I've found is to add a
pointer to A in B and init it the constructor of A using 'this'. Like
 
struct A {
int x;
struct B {
B(A *p) : parent(p) {}
A *parent;
void bar() { parent->x; }
};
A() : b(this) {}
};
 
But I'd like to avoid the pointer indirection, since the offset of B
in A is known at compile time. Is that possible?
 
Steve
"Alf P. Steinbach" <alf.p.steinbach@gmail.com>: Sep 14 09:32AM +0200

On 14 Sep 2022 08:55, Steve Keller wrote:
> };
 
> But I'd like to avoid the pointer indirection, since the offset of B
> in A is known at compile time. Is that possible?
 
For suitable restricted class types you can in principle use `offsetof`,
pointer arithmetic and `reinterpret_cast`.
 
But consider just using inheritance:
 
 
template< class Derived >
class B {
friend Derived;
int y;
public:
void bar() {
(void) Derived::x;
}
};
 
class A: B<A>
{
friend class B<A>;
int x;
public:
void foo() {
(void) y;
}
};
 
 
And having said that, consider the design. The need for two classes to
mutually access each others' data members is a design smell.
 
- Alf
"Alf P. Steinbach" <alf.p.steinbach@gmail.com>: Sep 14 09:46AM +0200

On 14 Sep 2022 09:32, Alf P. Steinbach wrote:
> On 14 Sep 2022 08:55, Steve Keller wrote:
 
Sorry that was a messed up incomplete example. Here's working full code:
 
 
#include <stdio.h>
 
template< class Derived >
class B {
friend Derived;
int y = 42;
public:
void bar() {
printf( "%d\n", static_cast<Derived*>( this )->x );
}
};
 
class A: public B<A>
{
friend class B<A>;
int x = 12345;
public:
void foo() {
printf( "%d\n", y );
}
};
 
auto main() -> int
{
A o;
o.foo();
o.bar();
}
 
 
If you do this (again, reconsider the design) then you can avoid much
verbosity by providing the `static_cast` via a member function e.g.
called `self`.
 
- Alf
Sam <sam@email-scan.com>: Sep 14 07:11AM -0400

Steve Keller writes:
 
> // I can access B's member y here. But can I somehow
> // do so using only y without the b. in front?
> b.y;
 
No. The only reason foo() can refer to x directly because x is a part of
this→.
 
> I could access b.y from A:foo() as only y if I add
 
> int &y = b.y;
 
Correct, that's how you'd do it.
 
> in struct A {}; but that adds a pointer to A and an additional pointer
> indirection with each access to b.y.
 
No, this doesn't add any pointer to any A. Additionally, you'll find out
that the resulting code will end up being identical to referencing b.y
explicitly, at least with moderate compiler optimizations enabled.
 
> But I can live with using b.y
> instead while only y would be more beautiful in this case.
 
Either way, the resulting code will be identical.
 
> To access a.x from B::bar() the only clean way I've found is to add a
> pointer to A in B and init it the constructor of A using 'this'. Like
 
Correct.
 
> };
 
> But I'd like to avoid the pointer indirection, since the offset of B
> in A is known at compile time. Is that possible?
 
Of course not, because C++ does not work like that. A given instance of "B"
has nothing, whatsoever, to indicate which given instance of A it's a member
of.
 
A a1;
A a2;
 
A::B b;
 
b.bar();
 
For a plain "x" referenced in bar(), which A do you expect to be accessed,
a1 or a2 here, and why exactly? Please be specific in your answer.
Richard Damon <Richard@Damon-Family.org>: Sep 14 07:44AM -0400

On 9/14/22 2:55 AM, Steve Keller wrote:
 
> But I'd like to avoid the pointer indirection, since the offset of B
> in A is known at compile time. Is that possible?
 
> Steve
 
Part of the issue is shown in a slightly more general case.
 
If struct A instead as
 
struct A {
int x;
struct B {
int y;
void bar();
} b1, b2;
void foo();
}
 
now, WHICH y in WHICH bx should foo access when it mentions y. your code
has a very special case.
 
Also if we add elsewhere a statement like:
 
A::B bg;
 
What x should bar access when it asks for x?
 
And even without that, how could bar in B, given just the address of the
B it is working on know where the x in the "containing" A would be, the
offset is different for b1 and b2.
 
Thus bar NEEDS a pointer to "its A", and foo NEEDS a pointer to the B is
wants to access, so the indirection in unavoidable, once B is made a
seperate class.
 
If there WILL be ONE and only one B inside of A, and that is the only
use of B, then making B a separate type is the source of the problem,
not something the language needs to help with. Just make y and bar a
member of A and that gets around the problem.
Anonymous <anonymous@anon.net>: Sep 14 12:55AM

The CIA dream is a world of big-eyed dumb emasculated nigger cattle with
no guns and no compiler with code in cloud GitHub under lock and key.
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: