Re: [Vala] C# conditional attributes in vala?



El 04/08/10 13:48, Abderrahim Kitouni escribió:
Hi,
                   في ث، 03-08-2010 عند 16:08 -0700 ، كتب Nigel Griffin:
Hi,

I have certain methods that I'd only like to be linked-in under certain circumstance (for performance 
reasons).  A real world example might be a need to log messages only from debug builds.

In C or C++, I could achieve this with a macro that would evaluate to a blank line when the appropriate 
flag is not set.

In C#, I could use conditional attributes to achieve the same result.

It's my understanding that there are no plans to ever add C style macros to Vala.  I was wondering if 
there were any plans to support C# conditional attributes in vala.  And if not, is there a way for me to 
advocate for the inclusion of Conditional Attributes into Vala?

In the mean time, it seems my only option is the rather inelegant solution of peppering my code with 
#if-#endif blocks.  If there is a vala solution, I am open to suggestions.
I think you would use the #if inside your "conditionally built"
function. This is used even in C when the macro for the same thing would
be non-trivial.

void cond_built(...) {
#if DEBUG
...
#endif
}

and you could even declare it inline so it's more like a macro.

Hey Abderrahim, maybe I'm missing something, but are you familiar with
Conditional attributes? You achieve what you just posted, but with
compiler sugar added so that the parts of the code that are not used are
still checked for compilation errors. See this post for a quick
exaplanation:

http://tirania.org/blog/archive/2010/Jun-12.html

Thus, I think this should be filed as an enhancement bug for the vala
compiler.

Regards,

  Andres

-- 






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]