Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

What will this output?

Name: Anonymous 2016-06-19 12:21

What will this program output?
Good luck, you'll need it!

#include <iostream>
using namespace std;

int main() {
class c {
public:
c() {
void f();
f();
}
};

c my_c();
}

void f() {
cout << "VALID C++" << endl;
}


The answer is absolutely nothing because c my_c(); is a fucking function declaration.

Name: Anonymous 2016-10-30 6:38

You're assuming the computer has memory protection.
I previously specified that that was one of the assumptions being made to demonstrate my point. But here's a program that does the same thing without depending on the assumption of memory protection:

#include <stdlib.h>
#include <stdint.h>

int main(void) {
uint8_t *ptr;
while(1) {
ptr = malloc(1);
if(ptr == NULL) {
puts("MEMORY ALLOCATION FAILURE");
return EXIT_FAILURE;
}
else *ptr = 111;
}
return EXIT_SUCCESS;
}


Now I'm sure someone will find some nitpick for why this wouldn't work, but this has the same expected behavior as the previous program: on a real computer, it would return with failure result, on a Turing machine it would never exit.

This version should work even without memory protection (as on a real machine, repeated calls to malloc() without calling free() should eventually use up all available memory and cause malloc() to return a null pointer). Again, we're to assume garbage collection (if available in the implementation) is disabled, and optimization is disabled, so the machine code generated is as close to possible to the source code.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List