Sunday, September 25, 2022

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

Muttley@dastardlyhq.com: Sep 25 08:50AM

On Sun, 25 Sep 2022 00:47:13 +0300
>> with it.
 
>Sure, although in my 30 years C++ I don't remember ever facing this
>problem. It is quite difficult to accidentally do this.
 
Many years ago faced with needing to access a private variable in a class
that didn't have a getter method written by a team that refused to provide one
for reasons I never understood, so I simply took the address of the first
public variable following it, counted back and derefrenced the pointer. Very
dodgy but it worked (until they changed the class layout obv).
 
eg:
 
#include <stdio.h>
 
class myclass
{
int i;
public:
int j;
myclass(): i(123) { }
};
 
 
int main()
{
myclass mc;
int *p = &mc.j;
--p;
printf("%d\n",*p);
return 0;
}
JiiPee <kerrttuPoistaTama11@gmail.com>: Sep 25 01:37PM +0300

> printf("%d\n",*p);
> return 0;
> }
 
Right, but it would never really come to my mind doing such things ...
unless I purposely did that for reasons like yours.
JiiPee <kerrttuPoistaTama11@gmail.com>: Sep 25 01:38PM +0300

> printf("%d\n",*p);
> return 0;
> }
 
I guess the power and the weakness also of the pointers
Bonita Montero <Bonita.Montero@gmail.com>: Sep 25 01:34PM +0200

> printf("%d\n",*p);
> return 0;
> }
 
Why not (&mc.j)[-1] ?
 
Bonita Montero <Bonita.Montero@gmail.com>: Sep 25 05:00PM +0200

Am 25.09.2022 um 13:34 schrieb Bonita Montero:
 
I'm asking myself if this and Mutterly's code is an
illegal aliasing which the compiler musn't notice.
Muttley@dastardlyhq.com: Sep 25 03:14PM

On Sun, 25 Sep 2022 13:34:59 +0200
>> return 0;
>> }
 
>Why not (&mc.j)[-1] ?
 
Never thought of that. Useful to remember if I need to do something similar
again.
Gawr Gura <gawrgura@mail.hololive.com>: Sep 25 09:22AM -0700

> Sure, although in my 30 years C++ I don't remember ever facing this
> problem. It is quite difficult to accidentally do this.
 
That being the case, why worry about someone mishandling a struct in C?
It's also quite difficult to accidentally write
 
str->length = 65535
 
when you meant to write
 
str->length
JiiPee <kerrttuPoistaTama11@gmail.com>: Sep 26 01:01AM +0300

On 25/09/2022 19:22, Gawr Gura wrote:
 
> str->length = 65535
 
> when you meant to write
 
> str->length
 
But I see other ways it could fail. Like imagine a funktion taking a
reference:
 
void foo(int a, int& l)
 
and then you call: foo(a, str->length);
If foo() changes the variable l, then lenght gets changed. And this
might be a mistake so that is not seeing the reference.
 
I mean, it opens much more doors to human mistakes or risks.
Richard Damon <Richard@Damon-Family.org>: Sep 25 07:02PM -0400

On 9/25/22 6:01 PM, JiiPee wrote:
> If foo() changes the variable l, then lenght gets changed. And this
> might be a mistake so that is not seeing the reference.
 
> I mean, it opens much more doors to human mistakes or risks.
 
But C doesn't have references, so you can't do that.
 
In C++, it would be private, so you couldh't do it.
Muttley@dastardlyhq.com: Sep 25 08:45AM

On Sat, 24 Sep 2022 12:33:03 -0700
>> higher speeds.
 
>I understand that the Spinal Tap compiler, written by Nigel Tufnel, goes
>up to 11.
 
+1
 
Though I doubt many on here will get it.
Manfred <noname@add.invalid>: Sep 25 07:31PM +0200

On 9/23/2022 9:50 AM, Juha Nieminen wrote:
 
> I wouldn't call embedded programming to be a "small niche".
 
> (Well, the subset of embedded programming that happens on processors
> so small that they can't run Linux, at least.)
 
Non-GC is definitely not for embedded programming only.
I have seen a pretty large project for digital imaging workstations fail
because of the non deterministic nature of GC.
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: