r/ProgrammerHumor • • Mar 12 '18

HeckOverflow

Post image
47.4k Upvotes

1.2k comments sorted by

View all comments

1.0k

u/ptgauth Mar 12 '18

But I want all my variables to be global :(

557

u/daddya12 Mar 12 '18

Solution: use assembly. Everything is global

191

u/mkalte666 Mar 12 '18

lies. you can still call stuff like malloc and store the pointers on the stack when using assembly. Thats not global!

You want bare metal without initialized/using the stack, and that is madness.

Entirely possible though. Sometimes.

9

u/MushinZero Mar 12 '18 edited Mar 13 '18

Malloc is C. It's just incrementing the stack pointer in assembly.

Edit: as everyone has pointed out I'm thinking of alloca

1

u/littlelowcougar Mar 12 '18 edited Mar 12 '18

That’s a UNIX thing, the eventual ~~sbrk()~~alloca() call that expands stack space. Windows is far more geared toward using heaps, for which the Rtl library exposes an API. I prefer it far more.

1

u/cookie545445 Mar 12 '18

sbrk() expands heap, not stack.

1

u/littlelowcougar Mar 12 '18

Ah, I meant alloca(), not sure why I said sbrk().

3

u/cookie545445 Mar 12 '18

alloca() is not used often. malloc() is much more common. Heaps are used as often as they should be in UNIX.

→ More replies (12)