add macro to disable the typedef of Thread or replace the typedef by a macro instead
SeleDreams opened this issue · comments
Hi, I was wondering if a macro could be added in order to disable the typedef of Thread that is defined in thread.h
(typedef struct Thread_tag* Thread;)
the reason is because i am am working on porting godot to 3ds and godot uses its own class named Thread, due to this it causes a redefinition issue which would require to change the naming of the classes of the entire engine just to add a platform
it would be better to be able to just have a macro like NO_THREAD_TYPEDEF to not typedef Thread and manually handle it, it could also be possible to replace the typedef by a #define to be able to undef it after importing 3ds.h
actually I thought of a good way to handle it
typedef struct Thread_tag* CTRThread;
#define Thread CTRThread
this way it's easy for users to undef it without it affecting much the internal codebase
I would instead recommend the following approach for handling name collision situations like this one:
- Only include libctru headers in the minimum number of source code files - especially not in headers that are included by a significant number of TUs.
- Wrap the libctru headers yourself (
#define Thread _3DS_Thread
or something, followed by#undef Thread
).
Note that changing the name of a C type will have side effects in C++ name mangling.
Macros simply replace identifiers by other sequences of tokens. You don't need to "undefine" any typedefs -- the C preprocessor is an earlier stage of source code processing. Doing this merely renames one identifier by another.
#define Thread _3DS_Thread
#include <3ds.h>
#undef Thread