What is the worst real-world macros/pre-processor abuse you’ve ever come across?

From memory, it looked something like this: #define RETURN(result) return (result);} int myfunction1(args) { int x = 0; // do something RETURN(x) int myfunction2(args) { int y = 0; // do something RETURN(y) int myfunction3(args) { int z = 0; // do something RETURN(z) Yes that’s right, no closing braces in any of the functions. … Read more

Preprocessor directives in Razor

I just created an extension method: public static bool IsDebug(this HtmlHelper htmlHelper) { #if DEBUG return true; #else return false; #endif } Then used it in my views like so: <section id=”sidebar”> @Html.Partial(“_Connect”) @if (!Html.IsDebug()) { @Html.Partial(“_Ads”) } <hr /> @RenderSection(“Sidebar”, required: false) </section> Since the helper is compiled with the DEBUG/RELEASE symbol, it works.

How to determine whether code is running in DEBUG / RELEASE build?

Check your project’s build settings under ‘Apple LLVM – Preprocessing’, ‘Preprocessor Macros’ for debug to ensure that DEBUG is being set – do this by selecting the project and clicking on the build settings tab. Search for DEBUG and look to see if indeed DEBUG is being set. Pay attention though. You may see DEBUG … Read more

#if DEBUG vs. Conditional(“DEBUG”)

It really depends on what you’re going for: #if DEBUG: The code in here won’t even reach the IL on release. [Conditional(“DEBUG”)]: This code will reach the IL, however calls to the method will be omitted unless DEBUG is set when the caller is compiled. Personally I use both depending on the situation: Conditional(“DEBUG”) Example: … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)