compiler-construction

What does the call stack look like in a system of nested functions, functions passed as arguments, and returned functions?

时间秒杀一切 提交于 2021-02-08 06:33:13
问题 Here is a made up example of nested functions with functions passed as parameters and functions returned: function foo() { let x = 100 function bar(a, b) { function mul(cb) { let m = x * a cb(m) } function add(cb) { let m = x + b cb(m) } function update(m) { x = m } mul(update) add(update) console.log(x) } return bar } let bar = foo() bar(2, 3) // => 203 bar(2, 3) // => 409 bar(2, 3) // => 821 bar(2, 3) // => 1645 Without figuring out potential ways in which these functions could be optimized

How come the compiler thinks this variable isn't constant?

纵饮孤独 提交于 2021-02-08 01:59:10
问题 This is my code: int main() { const int LEN = 5; int x[LEN]; } VS10 says: error C2057: expected constant expression error C2466: cannot allocate an array of constant size 0 error C2133: 'x' : unknown size I even tried the the code in this page and it gives the same problem (I commented the code which gives the error, and uncommented the correct one): http://msdn.microsoft.com/en-us/library/eff825eh%28VS.71%29.aspx If I was trying a crappy compiler, I would think it's a bug in the compiler,

How come the compiler thinks this variable isn't constant?

旧城冷巷雨未停 提交于 2021-02-08 01:58:12
问题 This is my code: int main() { const int LEN = 5; int x[LEN]; } VS10 says: error C2057: expected constant expression error C2466: cannot allocate an array of constant size 0 error C2133: 'x' : unknown size I even tried the the code in this page and it gives the same problem (I commented the code which gives the error, and uncommented the correct one): http://msdn.microsoft.com/en-us/library/eff825eh%28VS.71%29.aspx If I was trying a crappy compiler, I would think it's a bug in the compiler,

Delphi 6 Compiler Options (Pentium-safe FDIV)

元气小坏坏 提交于 2021-02-07 19:56:38
问题 I recieved a crash report from MadExcept from a user. The Exception was Invalid floating point operation. The odd part though is that the callstack dies at @FSafeDivide. I did a google and found out that this was a check for certain pentium chips which didn't do division correctly. If the test failed all the divisions would be done in software rather than hardware. I have the Pentium-Safe FDIV option turned on in my compiler settings. Could this have caused the error? I also read somewhere

Synthesized Properties and ivar error

£可爱£侵袭症+ 提交于 2021-02-07 18:11:09
问题 I've been building my program in the "Debug X86-64" mode (Xcode 3.6) and everything works flawlessly. However, I just tried switching to "Release X86-64" mode and upon compiling received the following errors for each of my properties: Synthesized property 'x' must either be named the same as a compatible ivar or must explicitly name an ivar. Where 'x' is one of my properties, the first being 'company' (I received 51 errors of this type.). In my .h interface file, I've listed the items this

What is the overhead for a method call in a loop?

我们两清 提交于 2021-02-07 14:24:24
问题 I’ve been working on a C# maze generator for a while which can generate mazes of like 128000x128000 pixels. All memory usage is optimized already so I’m currently looking at speeding the generation up. A problem (well more off an interest point) I found was the following (just some example code to illustrate the problem): This code runs in about 1.4 seconds on my machine when pixelChanged is null: public void Go() { for (int i = 0; i < bitjes.Length; i++) { BitArray curArray = bitjes[i]; for

Why doesn't the C# compiler catch an InvalidCastException [duplicate]

一曲冷凌霜 提交于 2021-02-07 11:56:16
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: Compile-time and runtime casting c# As I understand it, the following code will always compile, and will additionally always fail at run-time by throwing an InvalidCastException . Example: public class Post { } public class Question : Post { } public class Answer : Post { public void Fail() { Post p = new Post(); Question q = (Question)p; // This will throw an InvalidCastException } } My questions are... If my

Is it possible to generate ansi C functions with type information for a moving GC implementation?

半腔热情 提交于 2021-02-07 10:35:28
问题 I am wondering what methods there are to add typing information to generated C methods. I'm transpiling a higher-level programming language to C and I'd like to add a moving garbage collector. However to do that I need the method variables to have typing information, otherwise I could modify a primitive value that looks like a pointer. An obvious approach would be to encapsulate all (primitive and non-primitive) variables in a struct that has an extra (enum) variable for typing information,

Software Pipelining Example with GCC

雨燕双飞 提交于 2021-02-07 07:18:39
问题 I am looking for a real (source and generated code) example of software pipelining (http://en.wikipedia.org/wiki/Software_pipelining) produced by GCC. I tried to use -fmodulo-sched option when compiling for IA64 and PowerPC architectures by GCC versions 4.4-4.6 with no success. Are you aware about such example? The actual CPU architecture has no difference. Thank you 回答1: There are some tests from gcc testsuite for "-fmodulo-sched" option. You can check them: http://www.google.com/codesearch

how can I check if an object exists in C++

ぐ巨炮叔叔 提交于 2021-02-07 05:10:16
问题 I am trying to write a function that will check if an object exists: bool UnloadingBay::isEmpty() { bool isEmpty = true; if(this->unloadingShip != NULL) { isEmpty = false; } return isEmpty; } I am pretty new to C++ and not sure if my Java background is confusing something, but the compiler gives an error: UnloadingBay.cpp:36: error: no match for ‘operator!=’ in ‘((UnloadingBay*)this)->UnloadingBay::unloadingShip != 0’ I can't seem to figure out why it doesn't work. Here is the declaration for