I have started “containerizing” a number of my shared code to make sharing less labor intensive.
However, if I have a duplicated method in multiple shared objects, I run into the collision issue on compile.
Before I start removing pieces that will need to be replaced in other projects later, I was wondering if there was a conditional flag like we have in C/C++ to ignore a method if the method’s signature is already included.
None
You get the compiler warning then go use the compatibility flags to make one only compatible with a platform you’re not targeting and carry on
That way you can keep them but they wont get included
And … since we can’t know the order of the build, we can’t pre-set a variable in a master global module and then wrap the containerized methods with a #if Not DEFINED_METHOD_VAR …
That’s the same thing that Norman suggested above. It is a workaround, but it’s a hack. What I’ve done is to make the method Protected to the containerized code. That allows it to work in the test jigs for the containerized code, but not interfere with the master globals module.
I use it all the time when I’m moving code over from OPC to something more reasonable. I like to keep the old stuff around in case there are specific details hidden inside the methods, but I disable them with compile flags to follow the errors around.
Any time that I must modify settings for each build instead of providing a stable set of parameters across the code, I consider it a hack.
For example, the BRU engine code is written in C and ASM. It’s 128K lines of code in 121 modules (.c, .asm, .h). It compiles on 21 different Unix and Windows platforms with NO changes.
[quote=320557:@Tim Jones]Any time that I must modify settings for each build instead of providing a stable set of parameters across the code, I consider it a hack.
For example, the BRU engine code is written in C and ASM. It’s 128K lines of code in 121 modules (.c, .asm, .h). It compiles on 21 different Unix and Windows platforms with NO changes.[/quote]
How many #if’s (#ifdef etc) in it ?
I’d expect a pile (or the projects to build them exclude them as part of the project config)
I wouldn’t call it a hack - it’s basically xojo’s way of making it possible to do what #ifdef does in C allowing you to conditionally compile some methods for one target or another
Not much different than in each method using #if Target just that you can include exclude entire methods modules per target
Sure
In Xojo IF you were writing code from scratch you’d use one method and inside it use #if Target’s to run the right code
But thats not what you’re doing
I expect you would be shoving in all kinds of #ifdefs around code in C if you were doing about the same there
In C, I’d define the methods and do something like this:
#ifndef THIS_METHOD_DEFINED // only include the following code if it's not defined
#def THIS_METHOD_DEFINED // define it
... Stuff in method
#endif
That would allow multiple inclusions of a module’s contents (such as stdio.h) without the multiple inclusions from stepping on one another. Only the first inclusion of that wrapped code would be compiled into the final object code.
What I’m asking for in Xojo is slightly different in that I’m not trying to segment platform builds, but rather to limit the collision of two methods with the same name and signature.
[quote=320512:@Norman Palardy]None
You get the compiler warning then go use the compatibility flags to make one only compatible with a platform you’re not targeting and carry on
That way you can keep them but they wont get included[/quote]
[quote=320539:@Norman Palardy]you have no option to put code outside the declaration of the method anyway
Right, but the Protected flag prevents the global method/signature from competing and colliding with the containerized method/signature in the larger projects while allowing the containerized version to run as expected in the test jigs I’m creating for the testing of these modules.
Thus, I have a workaround that is better for what I’m trying to achieve than switching platforms on and off.