Saturday, July 18, 2020

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

Frederick Gotham <cauldwell.thomas@gmail.com>: Jul 18 07:29AM -0700

I have to write one source code file that will be common to three projects that are all different architectures (arm32, arm64, x86_64).
 
All 3 architectures have the same library, however the library in question is slightly altered for each architecture.
 
Note that I cannot alter the header files, nor can I use the size or modification date of the header file as an indicator of which architecture it is.
 
Library header file for 1st architecture:
 
struct Monkey {
int a;
};
 
Library header file for 2nd architecture:
 
struct Monkey {
int a, b;
};
 
Library header file for 3rd architecture:
 
struct Monkey {
int a, b, c;
};
 
And so then my single source file common to the three architectures would be something like:
 
#include "library_header.hpp"
 
int main(void)
{
Monkey obj;
 
obj.a = 1;
 
if constexpr ( contains_member(obj,b) )
obj.b = 2;
 
if constexpr ( contains_member(obj,c) )
obj.c = 3;
}
 
What is the cleanest way of doing this? Is there something in Boost for it?
 
Should I go with the first answer suggested by 'usta' here?:
https://stackoverflow.com/questions/12729827/c-conditional-compilation-based-on-member-presence
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Jul 18 05:49PM +0200

On 18.07.2020 16:29, Frederick Gotham wrote:
 
> What is the cleanest way of doing this? Is there something in Boost for it?
 
> Should I go with the first answer suggested by 'usta' here?:
> https://stackoverflow.com/questions/12729827/c-conditional-compilation-based-on-member-presence
 
You've abstracted away too much.
 
But generally this looks like you have a problem X, you have come up
with a possible solution Y, it turns out that Y is difficult or
practically impossible to implement in a clean way (or at all), so you
ask about Y.
 
Ask about X instead.
 
 
- Alf
Frederick Gotham <cauldwell.thomas@gmail.com>: Jul 18 09:35AM -0700

On Saturday, July 18, 2020 at 5:49:22 PM UTC+2, Alf P. Steinbach wrote:
 
> Ask about X instead.
 
> - Alf
 
 
 
If you're saying that I should change the header file or that I should ask someone to change the header file, well I can't.
"Öö Tiib" <ootiib@hot.ee>: Jul 18 09:56AM -0700

On Saturday, 18 July 2020 19:35:49 UTC+3, Frederick Gotham wrote:
 
> > - Alf
 
> If you're saying that I should change the header file or that I should ask someone to change the header file, well I can't.
 
I do not see that Alf suggested any solutions (like modifying
header file). Alf suggested to stop feeding us monkeys and tell
what really is different in interfaces of those implementations.
Your example of library I simply would not #include ever.
Barry Schwarz <schwarzb@delq.com>: Jul 18 10:33AM -0700

On Sat, 18 Jul 2020 07:29:59 -0700 (PDT), Frederick Gotham
 
>Library header file for 1st architecture:
 
> struct Monkey {
> int a;
 
#define my_Architecture_1
 
 
>Library header file for 2nd architecture:
 
> struct Monkey {
> int a, b;
 
#define my_Architecture_2
 
 
>Library header file for 3rd architecture:
 
> struct Monkey {
> int a, b, c;
 
#define my_Architecture_3
 
> Monkey obj;
 
> obj.a = 1;
 
> if constexpr ( contains_member(obj,b) )
 
#if defined(my_Architecture_2)
 
> obj.b = 2;
 

No comments: