i have these GNU macro:

#if defined __GNUC__
    #define EVENT [[gnu::weak]]
#elif defined __clang__
    #define EVENT [[llvm::weak]]
#endif
#define IS_EVENT_DEFINED(sym) (static_cast<bool>(sym))

these macro works fine. and help me test if the function(even with a prototype) was defined.
my problem is can i convert

[[gnu::weak]]

to Visual Studio code(for be compatible)?
because the Visual Studio don't have 'weak'

Recommended Answers

I read https://social.msdn.microsoft.com/Forums/vstudio/en-US/645d3065-85db-4ebf-ac20-70325dcc9318/c-how-use-weak-macro?forum=vclanguage and feel that you received some excellent replies there. I do get the feeling you want GCC in Visual Studio without any work. I could be wrong but that's the …

Jump to Post

I have to write that in decades of coding, never needed this. I see others also wrote same at https://stackoverflow.com/questions/8814705/how-to-check-if-the-function-exists-in-c-c

How would such compile if you were to call a non-existant function?

Jump to Post

All 5 Replies

I read https://social.msdn.microsoft.com/Forums/vstudio/en-US/645d3065-85db-4ebf-ac20-70325dcc9318/c-how-use-weak-macro?forum=vclanguage and feel that you received some excellent replies there. I do get the feeling you want GCC in Visual Studio without any work. I could be wrong but that's the feeling I got from reading that long discussion.

That said the most often this sort of thing comes up is someone is just wanting to use GCC code without a re-write. Sometimes it's unavoidable.

Here's what is likely going on:

This is something that doesn't work in the same way in Windows

So it's a PITR.

to be honest i don't get what i need.
i have 1 code for detect if the class have a function(even if is a prototype), but no for test if the function is defined :(
these macro help me do that, but isn't compatible with Visual Studio.
so let me ask you: how can i test if the function was defined?

i'm sorry, but do youy know how works 'weak' for, maybe, i create my own?
(the virtual functions from base class, on child\derived class, must have a prototype for i define them outside the class... i hate these rule :( )

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.