### midul's blog

By midul, 11 years ago,

in many code i see that type of "something". anybody explain please.

• +8

 » 11 years ago, # |   +3 It sets stack size. If you don't write it, your solution may crash with stack overflow (in deep recursive functions, for example).
•  » » 11 years ago, # ^ |   +15 The only thing to add is that it's MS Visual C++-specific and won't work with GCC. In GCC you should specify -Wl,--stack=256000000 command line option to set stack size (in bytes).
•  » » » 11 years ago, # ^ |   0 thats nice. by the by whats the default gcc stack size?
•  » » » » 11 years ago, # ^ |   0 2MB. You can see this in the headers of .exe produced by MinGW.
•  » » » 11 years ago, # ^ | ← Rev. 2 →   0 \$ g++ -Wl,--stack=256000000 test.cpp /usr/bin/ld: unrecognized option '--stack=256000000' /usr/bin/ld: use the --help option for usage information Parameter --stack can be used only with MinGW. ;)
•  » » » » 11 years ago, # ^ |   -13 so how increase stack in g++ under CNU/Linux?
•  » » » » » 11 years ago, # ^ |   +13 Nohow. Stack size is a user limit under GNU/Linux and doesn't depend on compiler. You can use ulimit -s to change/view it.
•  » » » 8 years ago, # ^ |   0 can you tell me exactly what should I write in the code for GCC compiler to increase the stack size?
•  » » » » 8 years ago, # ^ | ← Rev. 4 →   +21 If inline assembler is allowed, you can allocate a block of memory using malloc and move the stack pointer to that newly allocated block. AFAIK, it's the only way of increasing the stack size from the code in GCC. Sorry, but I don't know AT&T syntax, which is used by GNU Assembler, so I can't write the code.But in MSVC (which uses Intel syntax) it'd look like this: void main2() { // Do work } int main() { size_t stack_size = 1 << 26; char *newstack = (char*)malloc(stack_size); char *esp_pos = newstack + stack_size - sizeof(int); __asm { mov eax, esp_pos mov [eax], esp mov esp, esp_pos } main2(); __asm { pop esp } free(newstack); } UPD. Fixed an error.
•  » » » » 8 years ago, # ^ |   +10 You are not able to modify stack size from source code using GCC, afaik (however, I've heard that there were some extensions in the latest versions of GCC, but I don't know exactly). The only way to do so was described above. For example, in Windows you can use the following command line: g++ -o app.exe -Wl,--stack=256000000 -O2 source.cpp
•  » » » » 8 years ago, # ^ |   +5 Thanks both of you very much.
 » 11 years ago, # |   +8 “#pragma comment(linker, ”/STACK:36777216“)” Is it usable only in the on-line judge or anywhere you want?
•  » » 11 years ago, # ^ |   +8 It's usable anywhere with Microsoft Visual C++ — on your local machine and so on.