1
2
3
4
5
6
7
8
 

#if COMPILED

(* code to compile*) 

#endif 
By on 7/3/2010 5:50 AM ()

Thanks Desco.

By on 7/6/2010 5:05 PM ()

I don't understand the question. How is this a hack? It's exactly what you want?

By on 7/2/2010 12:09 PM ()

I thought one of the definitions of "hack" I'd heard over the years was a piece of code that does the job but doesn't seem very elegant or well constructed. I wasn't meaning to imply that this code doesn't work--only that it doesn't seem very elegant. I was hoping for a more elegant alternative.

By on 7/2/2010 1:24 PM ()

I guess I don't have enough imagination to picture a 'more elegant' way to conditionally compile code than #if ... #else ... #endif. What are you picturing?

By on 7/2/2010 1:47 PM ()

Actually, never mind. It's easy enough to simply write code like this:

1
2
3
4
5
6
7
8
(* code which should compile if SYMBOL is undefined *)

#if SYMBOL

    (* code which compiles in if SYMBOL is   defined *)

#endif

Which achieves the same effect anyway.

Since we've already had this long drawn out discussion, I'll just take a moment to try to explain what I was thinking of.

I've got years of C++ coding experience. With the C++ preprocessor, there's the

#ifdef but there's also a #ifndef which is sometimes handy if you only want to compile code in if a symbol is NOT defined. You don't have to write:

#ifdef SYMBOL

#else

/* code if SYMBOL is undefined */

#endif

You just write:

#ifndef SYMBOL

/* code if SYMBOL is undefined */

#endif

Granted it doesn't come up all that often (at least not in my experience) but there is a certain elegance and symmetry between having the two forms that mirror each other. I was just suggesting that it would be more elegant and more symmetrical if one didn't have to write

1
2
3
4
5
6
7
8
#if SYMBOL

#else

(* Code if symbol is undefined *)

#endif

in order to have code compiled only if a symbol is not defined. But as I say, this is really a moot point anyway because if a developer wants code compiled if some symbol is not defined all he (or she) has to do is to not put it within the #if/#endif construct.

I hope that explains what I was getting at a little better.

By on 7/2/2010 2:37 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper