compile-time

How functions are resolved by compiler?

孤者浪人 提交于 2019-12-04 15:13:57
How it is determined whether the below call is bound at compile time or at runtime? object.member_fn;//object is either base class or derived class object p->member_fn;//p is either base class or derived class pointer EDITED: #include <iostream> using namespace std; class Base { public: Base(){ cout<<"Constructor: Base"<<endl;} ~Base(){ cout<<"Destructor : Base"<<endl;} }; class Derived: public Base { //Doing a lot of jobs by extending the functionality public: Derived(){ cout<<"Constructor: Derived"<<endl;} ~Derived(){ cout<<"Destructor : Derived"<<endl;} }; void foo() { Base & Var = Derived(

Compile time operators in C

北战南征 提交于 2019-12-04 14:53:11
I'm familiar with only one compile time operator in C - sizeof . Are there any others that I as a programmer should be aware of? Only sizeof that I'm aware, although in C99 sizeof cannot be done at compile time for variable length arrays (VLAs). I think what you're grasping for but missing the terminology to describe is a constant expression or integer constant expression . The results of certain operators can be (integer) constant expressions if their operands are, and as you've pointed out, the result of sizeof can be even if its operand is not constant as long as it's not a VLA. See 6.6 in

Compile time and Run time in perl

自作多情 提交于 2019-12-04 12:27:42
问题 I am reading this document to understand the life cycle of a Perl program. I am unable to figure out when RUN time and when COMPILE time events occur while running a perl script on a command line like this: perl my_script.pl 回答1: perl script.pl will compile script.pl then execute script.pl . Similarly, require Module; will compile Module.pm then execute Module.pm . If the compiler encounters a BEGIN block, it will execute the block as soon as the block is compiled. Keep in mind that use is a

Creating a non-static version of compiler-based “dictionary” where keys are types

♀尐吖头ヾ 提交于 2019-12-04 09:49:33
There is a very easy trick which creates a dictionary-like structure where keys are types. The structure acts like a Dictionary<Type, T?> where keys are Type objects and values are instances of the corresponding types. This wonderful structure is as fast as just a variable or array since the "lookup" is only done once by the compiler/JITter and the proper value reference is compiled into your program. public static class MyDict<T> { public static T Value { get; set; } } You can work with that structure like this: MyDict<string>.Value = MyDict<int>.Value.ToString(); The problem is that this

Java get compile-time safe method name

放肆的年华 提交于 2019-12-04 09:39:44
While working with the reflection class and annotations I have found that there is no clear way to reference a method name in a compile-time safe way. What I really want is to be able to reference a method within an annotation. Might look something like: @CallAfter(method=Foo.class.foo()) void Bar() { ... } At the moment you can only do this with strings, which is not compile time safe.. This is a problem because it undermines Java being statically typed. The only solution I have found is something like what is below. However this still does not help with referencing a method in an annotation.

How do I parse a string at compile time in Nimrod?

风流意气都作罢 提交于 2019-12-04 07:34:43
Going through the second part of Nimrod's tutorial I've reached the part were macros are explained. The documentation says they run at compile time, so I thought I could do some parsing of strings to create myself a domain specific language. However, there are no examples of how to do this, the debug macro example doesn't display how one deals with a string parameter. I want to convert code like: instantiate(""" height,f,132.4 weight,f,75.0 age,i,25 """) …into something which by hand I would write like: var height: float = 132.4 var weight: float = 75.0 var age: int = 25 Obviously this example

Array Initialisation Compile Time - Constexpr Sequence

家住魔仙堡 提交于 2019-12-04 03:32:20
I was reading this question on SO. The question itself is not so interesting, but I was wondering whether it exists and how to implement a compile time solution. Regard to the first sequence: All numbers except the ones which can be divided by 3. The sequence should be something like: [1, 2, 4, 5, 7, 8, 10, 11, 13, 14, ...] By induction, I've found the math formula for that sequence: f(0) = 0; f(x > 0) = floor[(3x - 1) / 2]; So I've implemented a C++ constexpr function which generates the i-th number in the sequence: #include <type_traits> template <typename T = std::size_t> constexpr T

How to initialize a sequence of non-movable, non-copyable objects?

扶醉桌前 提交于 2019-12-04 03:31:35
问题 Let's say I have a type which is neither movable nor copyable: struct foo { explicit foo( size_t ){} ~foo(){} foo( foo const & ) = delete; foo( foo && ) = delete; foo& operator=( foo const & ) = delete; foo& operator=( foo & ) = delete; }; Now given a number known at compile time (call it N), is there any way that I can create a "sequence" of these on the stack with each one initialized with numbers 0 through N-1? I would be satisfied with a C-style array foo[N] , a std::array< foo, N > , or

Scala slow builds: development approaches to avoid

社会主义新天地 提交于 2019-12-03 17:11:13
问题 First of all, incremental builds via SBT are pretty awesome, generally in the < 1sec range. However, sometimes you have to do a full clean/compile, or, in the case of incremental builds, you make a change to one file which then triggers the compilation of dozens of other files. This is when Scala development becomes less...fun, as the resulting slowdown in work flow can encourage context switching (check email, latest Stackoverflow threads, etc.), which subtly makes one less productive So,

Constexpr variable evaluation

北城以北 提交于 2019-12-03 17:06:14
Here is my code and I need clarification on what's happening: constexpr int funct(int x){ return x + 1; } int main(){ int x = funct(10); return 0; } constexpr 's allows compile time calculation, and based on my code above, since funct is declared as constexpr , it is allowed to do compile time calculations if the arguments are constants or constexpr's themselves. The part that I am confused with lies in this part, the int x . Since it is not declared as constexpr , would it mean that int x will get the value at runtime? Does that mean that declaring it to be constexpr int x will mean that int