-3
#include <stdio.h>
#include <math.h>
int main()
{   printf("Hello World! \n");
    double a = 56;
    double b = pow(a,a);
    double c = pow(b,b);
    double d = pow(c,c);
    double e = pow(d,d);
    printf("%lf\n", e);
    return 0;
}

when i run it, I am greeted with 'Hello World' and then 'inf'.... The aim is to create a C programme that can crash a computer bypassing OS interventions, if that is at all plausible ?

An Ant
  • 184
  • 1
  • 10

1 Answers1

-1

pow(a,a) already has 98 decimal digits

e goes beyond std::numeric_limits<double>::max()

I don't know where to use pow(56, 56).

In c++ we have a "boxes" with size 1, 2, 4, 8 byte(s). To solve most problems this is enough. However, sometimes required operations with large numbers. For large numbers can be used boost::multiprecision. But for some tasks this may not be enough.

But c++ doesn't care about that, because c++ cares about performance.

Do you know about cpu-cache? Look how-do-cache-lines-work.

Whenever the processor wants to fetch data from main memory, first it will look at the cache buffer to see whether the corresponding address is present in the buffer. If it is there, it will perform the operation by using the cache; no need to fetch from the main memory. This is called a "Cache hit".

If the address is not present in the cache, it is called a "Cache miss". If a cache miss has occurred, that means the processor has go to main memory to fetch the address and it takes some more time.

Anton Shwarts
  • 515
  • 2
  • 10
  • right so doing this wont be possible ? but python tries... – An Ant Jun 16 '20 at 04:25
  • I will try to update my answer so that it is clear – Anton Shwarts Jun 16 '20 at 04:27
  • @AnAnt "right so doing this wont be possible ?" - It's without a doubt impossible. "but python tries" - Unless you have a computer with practically infinite amounts of memory and an infinite amount of time, it'll never finish. – eesiraed Jun 16 '20 at 04:39
  • the aim for me wasnt to get an answer but to crash my computer, which i was hoping C could do as well as python... – An Ant Jun 16 '20 at 04:41
  • @AnAnt I updated the answer. And You can write your library for this, or search for a ready-made one. – Anton Shwarts Jun 16 '20 at 04:44
  • @AnAnt C++ doesn't have arbitrary precision arithmetic built in. All your fundamental arithmetic types are fixed size and have a finite range and precision. If you want to crash your computer you can try `while (true) { new int; }` which will continuously attempt to allocate more and more memory but a modern OS will just kill your program when it allocates too much memory. – eesiraed Jun 16 '20 at 04:45
  • @AnAnt what!? Python **most certainly** cannot do this any better than C. Ah except crashing the computer. – Antti Haapala -- Слава Україні Jun 16 '20 at 04:45
  • im new, so not sure what exactly you mean... a similar python programme runs (forevr until all resources are used up) so how to replicate it with C? assuming no interference from OS – An Ant Jun 16 '20 at 04:46
  • Just malloc a bunch without freeing? – Putnam Jun 16 '20 at 04:47
  • "a similar python programme runs (forevr until all resources are used up)" - Your operating system should eventually stop it and prevent the whole computer from crashing. – eesiraed Jun 16 '20 at 04:48
  • I am new (less than a week) with C. I intend to make something that can crash a computer, and i tried to use all resources to crash it. I know more Python, and in Python, running something like this should be able to use all RAM... and it runs almost indefinitely. With C, this isnt working the same way. What exactly should I do to replicate something similar in C ? (please remember I'm very new) – An Ant Jun 16 '20 at 04:50
  • Also perhaps there is a way to bypass the OS intervention in C, considering its very close to the hardware ? – An Ant Jun 16 '20 at 04:51
  • @AnAnt You can try to allocate infinite amounts of memory with `while (true) { new int; }`, but it's highly unlikely that you'll be able to crash your computer with a single program. "Also perhaps there is a way to bypass the OS intervention in C, considering its very close to the hardware ?" - Possibly, but not easily. An modern PC OS shouldn't allow you to do that easily. – eesiraed Jun 16 '20 at 04:52
  • I do not understand why this answer goes on to start talking about CPU cache lines. While most of what it says is true enough, it has absolutely no relevance to what is asked in the question. – Cody Gray - on strike Jun 16 '20 at 05:05