#array code breaks
45 messages · Page 1 of 1 (latest)
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.
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.
yep, and the code uses exactly 8 MB of memory when it doesn't work anymore according to my math, so they probably have a stack size limit of 8 MB
and changing it to long long causes it to fail at 127, so its definitely the stack limit
you can most likely increase the limit with e.g. ulimit -s 10240
but otherwise what love said
;compile ulimit -s 10240 c++ int main() { char array[256][256][128]; return 0; }
/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
hmmmmmmmmmmmm
@hollow wren Has your question been resolved? If so, run !solved :)
how did you even get that far..... my compiler screams at me for exceeding 32k
;compile ```c
int main() {
char array[256][256][127];
return 0;
}
No output.
until you access it, it's probably removed; so your code did nothing
I've checked with access locally, to last and first element and my stack limit
;compile ```c
int main() {
char array[256][256][128];
return 0;
}
I can get it both crashing or going further
No output.
oh, i need to print it
depending on the limit
so with my default limit of 8MB 256x256x127 was still fitting and working, x128 crashing before increasing the limit
;compile ```c
int main() {
long long array[256][256][128];
return array[1][10][100];
}
Program terminated with signal: SIGSEGV
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];
}
Program terminated with signal: SIGSEGV
;compile
int main(void)
{
char a[256][256][128];
a[0][0][0] = 1;
a[255][255][127] = 1;
}
Program terminated with signal: SIGSEGV
;compile ```c
int main() {
char array[256][256][255];
return array[1][10][100];
}
Program terminated with signal: SIGSEGV
;compile ```c
int main() {
char array[256][256][127];
array[0][0][0] = 1;
array [255][255][127] = 1;
return 0;
}
No output.
ok, the limit increased by 1, to 129
?
.
oh