This question already has answers here:
When have you come upon the halting problem in the field? [closed]
(13 answers)
Closed 9 years ago.
I'm building a compiler for a custom language. Is it possible for the compiler to detect any infinite looping condition without running the program?
If so how can I implement it?
You may be able to detect some infinite loops, but in general you can't detect all possible infinite loops (unless your custom language is specifically designed to eliminate general looping constructs). See http://en.wikipedia.org/wiki/Halting_problem.
Related
This question already has answers here:
Recursion or iteration?
(14 answers)
Closed 2 years ago.
What is the difference between loops and recursion and which one is more preferred for solving a problem?
Loop is repeated execution of a block of code until the given condition is false.Loop has a linear flow from initial condition to terminating condition.
On the other hand recursion is a method/function being called by itself. Recursion takes place creating stack of task ie, each calling function returns to its caller function after execution.
Loop and recursion aren't exactly alternatives to have preferences, they are used for different type of tasks.
This question already has answers here:
What is the full "for" loop syntax in C?
(6 answers)
Closed 5 years ago.
My question is simple,thus I will not go in deep
can we use for() loop without condition like this
for(;;space+=1)
{
printf(" ");
break;
}
Of course you can. An empty condition is taken to evaluate to 1.
for (;;){/*ToDo - your code here*/} is idiomatic C.
Yes it is perfectly correct to do so.
But since you have provided a break immediately after printf, it will only execute once. I'm not sure whether this is what you wanted. But if so, then this works fine.
This question already has answers here:
Is there an interpreter for C? [closed]
(13 answers)
Closed 7 years ago.
I'm not looking for csh, I'm looking for a shell for C similar to the Python or the Scala shells.
I understand that C is a compiled language, but is there anything out there that would let me quickly play around with things so I can e.g. better learn how pointers work? It should at least be theoretically possible to do this, wondering if anyone has taken the time to implement it.
As you well know that C is a compiled language. It is better to write C code than compile it, do some breakpoints, learn what value is in memory, where the pointer points etc.
But I think you mean this. Is there an interpreter for C?
This question already has answers here:
Are there any solid large integer implementations in C? [closed]
(7 answers)
Closed 8 years ago.
Recently in programming contest in Here, the problem is pretty straight forward but catch is with worst case scenario which we have to handle data of size 10^10000 .
I tried the program in python which is straight forward as i don't have to specify the datatype(It is taken care by the compiler ) but when i tried with C I couldn't find the correct datatype .
(I tried uintmax_t which didn't work out too).
So how to approach very huge type of data's in C ?
There is no built-in datatype in C that can store that big values. You will either have to write your own implementation or use a library. As this is a competition, though the second is not an option. Every now and then similar problems appear and usually the best approach is to use another language e.g. java(as it is usually available on competitions).
This question already has answers here:
Why choosing for (;;){} over while(1)? [duplicate]
(4 answers)
Closed 9 years ago.
why c language needs this for(; ;) loop ? It is actually an infinite loop and while(1) also infinite loop. My question is that which one we should use ? I want to know which one is more efficient according to compiler point of view?
Both are same. I believe infinite loops are needed when you want to break on a certain condition which the executing code knows only once it enters the loop.
For me this looks more intuitive and easier:
while(1) {}
while(true) {}
Remember even this is an infinite loop :
// just don't provide the condition
for(int i=0; ;i++) // don't mind the syntax as I don't belong to C
Whichever fits your needs. Both do the same thing.
For an infinite loop, both do the same thing, but for and while are used for different things, and are not generally interchangeable.