compile-time

ASP.NET Resourcing: Detect when ResourceProvider is invoked at compile-time vs. run-time

My ASP.NET web app utilizes a custom resource provider backed by a SQL Server data store. As I understand it, implicit resourcing invokes the resource provider at compile-time to determine whether or not resource expressions need to be generated for the given resourcekey. Consequently, my build process is now dependent upon having a li...

Compile-time lookup array creation for ANSI-C?

A previous programmer preferred to generate large lookup tables (arrays of constants) to save runtime CPU cycles rather than calculating values on the fly. He did this by creating custom Visual C++ projects that were unique for each individual lookup table... which generate array files that are then #included into a completely separate A...

Haskell compile time function calculation

I would like to precalculate values for a function at compile-time. Example (real function is more complex, didn't try compiling): base = 10 mymodulus n = n `mod` base -- or substitute with a function that takes -- too much to compute at runtime printmodules 0 = [mymodulus 0] printmodules z = (mymodulus z):(...

convincing C# compiler that execution will stop after a member returns

I don't think this is currently possible or if it's even a good idea, but it's something I was thinking about just now. I use MSTest for unit testing my C# project. In one of my tests, I do the following: MyClass instance; try { instance = getValue(); } catch (MyException ex) { Assert.Fail("Caught MyException"); } instance.d...

Is sizeof in C++ evaluated at compilation time or run time?

For example result of this code snippet depends on which machine: the compiler machine or the machine executable file works? sizeof(short int) ...

Compile time Meta-programming, with string literals.

I'm writing some code which could really do with some simple compile time metaprogramming. It is common practise to use empty-struct tags as compile time symbols. I need to decorate the tags with some run-time config elements. static variables seem the only way to go (to enable meta-programming), however static variables require global d...

What libraries use design patterns implemented with compile-time metaprogramming techniques?

Does anybody know of any libraries that use design patterns that are implemented using compile-time techniques e.g. template metaprogramming? I know that Loki implements a few but I need to find other libraries. ...

How To Get the Name of the Current Procedure/Function in Delphi (As a String)

Is it possible to obtain the name of the current procedure/function as a string, within a procedure/function? I suppose there would be some "macro" that is expanded at compile-time. My scenario is this: I have a lot of procedures that are given a record and they all need to start by checking the validity of the record, and so they pass ...

How to reduce compile time with C++ templates

I'm in the process of changing part of my C++ app from using an older C type array to a templated C++ container class. See this question for details. While the solution is working very well, each minor change I make to the templated code causes a very large amount of recompilation to take place, and hence drastically slows build time. ...

Is typeid of type name always evaluated at compile time in c++ ?

I wanted to check that typeid is evaluated at compile time when used with a type name (ie typeid(int), typeid(std::string)...). To do so, I repeated in a loop the comparison of two typeid calls, and compiled it with optimizations enabled, in order to see if the compiler simplified the loop (by looking at the execution time which is 1us ...

best-practice on for loop's condition

what is considered best-practice in this case? for (i=0; i<array.length(); ++i) or for (i=array.length()-1; i>=0; --i) assuming i don't want to iterate from a certain direction, but rather over the bare length of the array. also, i don't plan to alter the array's size in the loop body. so, will the array.length() become constant ...

organize using directives, re-run tests?

Before making a commit, I prefer to run all hundred-something unit tests in my C# Solution, since they only take a couple minutes to run. However, if I've already run them all, all is well, and then I decide to organize the using directives in my Solution, is it really necessary to re-run the unit tests? I have a macro that goes throug...

Getting compilation timestamp of a java class

Is it possible to reliably determine the compilation time stamp of a given class for both java applications running locally and as applets and/or JNLP webapps ? ...

Disable logging in Java at compile time

I have some Java code that I'd like to instrument with log messages for debugging purposes. The final (compiled) production code, however, should not contain any logging as it would slow down the execution time. Is there any way in Java to disable a logger at compile time? I am not afraid of the footprint a check inside the log method o...

Delphi {$IFDEF CONSOLE} Problem

I just tried program Project1; {$APPTYPE CONSOLE} uses SysUtils; begin {$IFDEF CONSOLE} beep; {$ENDIF} end. and expected to hear a beep during runtime, but not. The following test works, though: if IsConsole then beep; Why doesn't the compile-time test work? As far as I can understand from this doc, it sure shoul...

Dynamic hash->class tag

I have: const unsigned int hash_1 = 0xaf019b0c; const unsigned int hash_2 = 0xf864e55c; const unsigned int hash_3 = 0xfaea8ed5; Hashes come from an automatically generated header. These hashes are indirectly associated with tags 1, 2, 3. The tags are associated with classes through a simple compile-time generated id. That way I can ...

Static assert in C

What's the best way to achieve compile time static asserts in C (not C++), with particular emphasis on GCC? ...

How to determine the length of an array at compile time?

Are there macros or builtins that can return the length of arrays at compile time in GCC? For example: int array[10]; For which: sizeof(array) == 40 ???(array) == 10 Update0 I might just point out that doing this in C++ is trivial. One can build a template that returns the number inside []. I was certain that I'd once found a len...

How do make C++ create an expression that uses compile-time checking for constants and asserts for variables?

Here’s an example setup… a macro or a template CHECKEXPR_RETURNVAL(EXPR,VAL) that checks that EXPR is TRUE while returning VAL. This is useful in a variety of places -- like in this highly simplified example: #define ISPOW2(VAL) ((0!=VAL)&&(0==(VAL&(VAL-1)))) #define _ALIGNPOW2(VAL,ALIGN) ((VAL+(ALIGN-1))&(~(ALIGN-1))) #defi...

C++ boost variant question

Hello! I know that boost::variant uses boost::mpl stuff behind it and has a mpl-compatible typedef types. Let's say I have a simple typedef: typedef boost::variant<bool, int> Variant; Now I have another template function, let's say: template <typename T> T function() { // ... } I want this function to act differently for two ca...