Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Most Sacrilegious Code I've Ever Written

66 views
Skip to first unread message

cauldwel...@gmail.com

unread,
Jul 11, 2019, 4:53:57 AM7/11/19
to

Hi guys it's Frederick from 15 years ago. I work fulltime as a firmware engineer now.

I think today I wrote the most sacrilegious code I've ever written.

struct Param {

struct Dummy {

operator unsigned() { return 0; }

operator void*() { return 0; }

};

Dummy operator&() const
{
return Dummy();
}
};

Öö Tiib

unread,
Jul 11, 2019, 10:52:46 AM7/11/19
to
Common reason of overloading address of operator is that then we can
handle objects that are masquerading as (for example because of being
proxy to) some other objects more conveniently and/or more confusingly.

Your Parameter seems to be proxy to nothing. I don't see how it
can be useful even in unit test. OTOH big part of C++ code out there
is useless so it is not sacrilegious to write some more.

Frederick Gotham

unread,
Jul 15, 2019, 5:10:30 AM7/15/19
to
I'm part of a team that writes the firmware for an embedded device.

I was told that the firmware used a 3rd party library that has been updated from Version 1 to Version 2. Version 2 is very different, it has a different API. Different functions, different structs, different enums.

After changing the Makefile for my own project code to accomodate version 2 of the 3rd party library, I got a load of compiler and linker errors.

I needed to get the entire project to compile, so I made a header file called "fake_stuff.hpp" to accommodate the differences in the new version of the 3rd party library. I had to make that "Param" class to get everything to compile.

Öö Tiib

unread,
Jul 15, 2019, 6:33:07 AM7/15/19
to
I'm still confused about the whole scenario.
I imagine template (like X) in the new interface of 3rd party library.
That X expects template class argument (like X<T>).
Implementation of that X expects result of address of
operator applied to const instance of T to be default-convertible
into pointer to mutable void and to unsigned? And then you wrote
the Parameter to satisfy concept of that T.
That sounds hard to believe so perhaps I am not understanding the
whole story.

Frederick Gotham

unread,
Jul 15, 2019, 7:19:24 AM7/15/19
to
On Monday, July 15, 2019 at 11:33:07 AM UTC+1, Öö Tiib wrote:

> > I needed to get the entire project to compile, so I made a header file called "fake_stuff.hpp" to accommodate the differences in the new version of the 3rd party library. I had to make that "Param" class to get everything to compile.
>
> I'm still confused about the whole scenario.
> I imagine template (like X) in the new interface of 3rd party library.
> That X expects template class argument (like X<T>).
> Implementation of that X expects result of address of
> operator applied to const instance of T to be default-convertible
> into pointer to mutable void and to unsigned? And then you wrote
> the Parameter to satisfy concept of that T.
> That sounds hard to believe so perhaps I am not understanding the
> whole story.



Wanna see the compiler errors I get without my crazy class?


James Kuyper

unread,
Jul 15, 2019, 8:59:56 AM7/15/19
to
Yes, along with the code that triggered those errors and, for every class relevant to those error messages, enough of the definition to understand what those messages mean. Note: if you weren't sure what those messages meant, be VERY cautious about dropping something just because you think it's not relevant.
0 new messages