stack-overflow

Why does a recursive call cause StackOverflow at different stack depths?

雨燕双飞 提交于 2019-11-29 19:42:01
I was trying to figure out hands-on how tail calls are handled by the C# compiler. (Answer: They're not. But the 64bit JIT(s) WILL do TCE (tail call elimination). Restrictions apply .) So I wrote a small test using a recursive call that prints how many times it gets called before the StackOverflowException kills the process. class Program { static void Main(string[] args) { Rec(); } static int sz = 0; static Random r = new Random(); static void Rec() { sz++; //uncomment for faster, more imprecise runs //if (sz % 100 == 0) { //some code to keep this method from being inlined var zz = r.Next();

How to show code snippets in MS Word document as it shows in StackOverflow (scrollbars and gray background)

蹲街弑〆低调 提交于 2019-11-29 19:06:52
问题 I am writing a document which intends to show code changes made in C# project, I am looking for a good format to show code snippet. I like is the way StackOverflow site shows code snippet in its Questions and Answers (scrollbars and background color). Can anybody guide me to create similar background/view to show code snippet in word document (mainly scrollbars). I tried copying and pasting it from StackOverflow but the background does not appear. I search and found this useful link but it

Why do I get a StackOverflowException with my property?

£可爱£侵袭症+ 提交于 2019-11-29 18:25:21
Please explain to me why this code produces a StackOverflowException . There is a mistake in one of the lines as I have shown using comment. I do not however understand why this gives me a StackOverflowException . class TimePeriod { private double seconds; public double hour { get { return hour / 3600; } // should be : get { return seconds / 3600; } set { seconds = value * 3600; } } } class Program { static void Main() { TimePeriod t = new TimePeriod(); t.hour = 5; System.Console.WriteLine("Time in hours: " + t.hour); } } Christos This produces a stack-overflow, because there is a recursive

Recursive main() - why does it segfault?

浪子不回头ぞ 提交于 2019-11-29 18:24:15
问题 Why does the following program segfault? int main() { main(); } Even though it is a recursion that does not end and is therefore invalid by definition, I don't see why it segfaults (gcc 4.4.3 and clang 1.5 (trunk)). 回答1: Because every time it calls itself it allocates a little bit of stack space; eventually it runs out of stack space and segfaults. I'm a bit surprised it goes with a segfault, though; I would have expected (drum roll) stack overflow! 回答2: You get a stack overflow (!) 回答3: int

rake aborted! stack level too deep [duplicate]

[亡魂溺海] 提交于 2019-11-29 17:57:52
问题 Possible Duplicate: Rails 3.0 & Ruby 1.9.2rc: Rake commands return 'already initialized constant' & stack level too deep errors. Any ideas Am using Ruby version 1.9.1 on windows vista. Am getting the rake aborted error for any rake commands am using. This does not happen in all my app folder. Its happening only on a specific app folder. C:\rails_project\stunetwork>rake db:reset (in C:/rails_project/stunetwork) rake aborted! stack level too deep C:/Ruby191/lib/ruby/gems/1.9.1/gems/rake-0.8.7

Getting StackOverflowException when setting property

限于喜欢 提交于 2019-11-29 17:07:27
public List<Empleado> ListarEmpleados() { List<Empleado> returnList = new List<Empleado>(); var lista = from u in DB.tabEmpleado select new { u.idEmpleado, u.idUsuario, u.Nombre, u.Apellidos, u.Telefono1 }; foreach (var e in lista) { Empleado empleado = new Empleado(); empleado.idEmpleado = e.idEmpleado; empleado.idUsuario = e.idUsuario; empleado.nombre = e.Nombre; empleado.apellidos = e.Apellidos; empleado.telefono1 = e.Telefono1; returnList.Add(empleado); } return returnList; } This is a WCF service, when is called it returns StackOverflow error in the class definition, exactly in the Set

How to avoid StackOverflowError for a recursive function

China☆狼群 提交于 2019-11-29 16:59:30
问题 I'm writing a function that will call itself up to about 5000 times. Ofcourse, I get a StackOverflowError . Is there any way that I can rewrite this code in a fairly simple way?: void checkBlocks(Block b, int amm) { //Stuff that might issue a return call Block blockDown = (Block) b.getRelative(BlockFace.DOWN); if (condition) checkBlocks(blockDown, amm); Block blockUp = (Block) b.getRelative(BlockFace.UP); if (condition) checkBlocks(blockUp, amm); //Same code 4 more times for each side } By

What is the use of -fno-stack-protector?

人盡茶涼 提交于 2019-11-29 16:51:42
问题 I have written an application in C, and I'm trying to understand what is the purpose of the -fno-stack-protector command when compiling. For my specific application, it makes no difference if I use this command or not in terms of protecting against buffer overflow. I've read online that the -fstack-protector and -fno-stack-protector commands enable and disable respectively the stack-smashing protector, but if I'm compiling the application myself, how can the protector be enabled beforehand?

Stack Overflow error occurs when using recursive fibonacci function

删除回忆录丶 提交于 2019-11-29 16:14:54
Here's my code and it runs well with values of 400 to 4000 but once it's about 4mil, I get stack overflow errors. Thanks in advance! public class Fib { static int c=1,b=2; static long sum1=0,sum2=0; static long fib(long a){ if(a==1){ return 1; } if(a==2){ return 2; } else{ return fib(a-1)+fib(a-2); } } public static void main(String[] args){ sum2= fib(4000000); System.out.println("Sum %f" +sum2); } } Yes - you're running out of stack space. It's far from infinite, and you're using it up on each recursive call. You're trying to end up with a stack with 4 million stack frames - that's not going

Android StackOverflow Error

与世无争的帅哥 提交于 2019-11-29 15:59:45
The following is my stacktrace. I looked through it but it just shows a bunch of views and frankly I'm not too sure what a stackoverflow error is exactly. I read on some of the other questions that some solved theirs through iterations (again, no idea what those are). For the basic layout of the app this is coming from when this crashes is: TabView (5 tabs) > 5th tab > webview in that tab on button press. Now it does actually crash until i hit the back button to go back to the 5th tab and it doesn't do it every time. Thanks for the help! Edit: I stopped testing on the emulator and I have yet