#array code breaks

45 messages · Page 1 of 1 (latest)

hollow wren
#
int main() {
    char array[256][256][128];
    return 0;
}

[127] will work, 128 will not. Why?

twin jewelBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

prisma sable
#

That is too much for the stack. You could move it outside of main and make it static, but is better to allocate it on the heap.

red estuary
worthy jewel
#

sounds like Linux

#

iirc on Windows it's 1 MB

#

on Linux 8

red estuary
#

and changing it to long long causes it to fail at 127, so its definitely the stack limit

hollow wren
#

Interesting.

#

Thanks guys 👍

worthy jewel
#

you can most likely increase the limit with e.g. ulimit -s 10240

#

but otherwise what love said

red estuary
#

;compile ulimit -s 10240 c++ int main() { char array[256][256][128]; return 0; }

tacit steppeBOT
#
Compiler Output
/opt/compiler-explorer/gcc-13.2.0/bin/../lib/gcc/x86_64-linux-gnu/13.2.0/../../../../x86_64-linux-gnu/bin/ld: cannot find ulimit: No such file or directory
/opt/compiler-explorer/gcc-13.2.0/bin/../lib/gcc/x86_64-linux-gnu/13.2.0/../../../../x86_64-linux-gnu/bin/ld: cannot find 10240: No such file or directory
collect2: error: ld returned 1 exit status
Build failed
red estuary
#

hmmmmmmmmmmmm

twin jewelBOT
#

@hollow wren Has your question been resolved? If so, run !solved :)

astral basalt
#

how did you even get that far..... my compiler screams at me for exceeding 32k

red estuary
#

;compile ```c
int main() {
char array[256][256][127];
return 0;
}

tacit steppeBOT
#
Compilation successful

No output.

astral basalt
#

until you access it, it's probably removed; so your code did nothing

worthy jewel
#

I've checked with access locally, to last and first element and my stack limit

red estuary
#

;compile ```c
int main() {
char array[256][256][128];
return 0;
}

worthy jewel
#

I can get it both crashing or going further

tacit steppeBOT
#
Compilation successful

No output.

red estuary
#

oh, i need to print it

worthy jewel
#

depending on the limit

#

so with my default limit of 8MB 256x256x127 was still fitting and working, x128 crashing before increasing the limit

red estuary
#

;compile ```c
int main() {
long long array[256][256][128];
return array[1][10][100];
}

tacit steppeBOT
#
Compiler Output
Program terminated with signal: SIGSEGV
red estuary
#

no its giving different results to before

#

long long finally gives a sigsegv, so the limit somehow increased

#

;compile ```c
int main() {
char array[256][256][256];
return array[1][10][100];
}

tacit steppeBOT
#
Compiler Output
Program terminated with signal: SIGSEGV
worthy jewel
#

;compile

int main(void)
{
    char a[256][256][128];
    a[0][0][0] = 1;
    a[255][255][127] = 1;
}
tacit steppeBOT
#
Compiler Output
Program terminated with signal: SIGSEGV
red estuary
#

;compile ```c
int main() {
char array[256][256][255];
return array[1][10][100];
}

tacit steppeBOT
#
Compiler Output
Program terminated with signal: SIGSEGV
red estuary
#

;compile ```c
int main() {
char array[256][256][127];
array[0][0][0] = 1;
array [255][255][127] = 1;
return 0;
}

tacit steppeBOT
#
Compilation successful

No output.

red estuary
#

ok, the limit increased by 1, to 129

worthy jewel
#

no, it did not

#

you are testing it wrong

red estuary
#

?

red estuary
#

oh