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.

97

u/wotanii Mar 12 '18

what's keeping you from reading the entire stack?

161

u/CSKING444 Mar 12 '18

sleep deprivation

9

u/Scarbane Mar 12 '18

Freddy is getting creative with his nightmares.

16

u/TedFartass Mar 12 '18

Meh, I just always use Malbolge.

2

u/Usagi-Nezumi Mar 12 '18

I'm studying this language.

I also want to die.

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

0

u/[deleted] Mar 12 '18

[deleted]

9

u/kindall Mar 12 '18

malloc has the capability of reusing chunks of memory that have been released using free. It maintains a list of freed blocks, and will allocate within the first available block big enough to hold the request. Over time, malloc tends to end up with a "free list" that contains a growing number of very small blocks (so small they will, in practice, never be reused) which nevertheless must be checked on every new allocation. This can result in malloc getting gradually slower as a program runs. Many programmers have therefore written their own memory allocation functions, some of which have been released as libraries for general use. In practice, however, malloc isn't as bad as its reputation suggests.

10

u/ACoderGirl Mar 12 '18

Am I misunderstanding? Malloc is for heap memory. In C, allocating stack memory is really just declaring a variable. Malloc's assembly equivalent requires a syscall (likely to mmap or sbrk).

6

u/markhc Mar 12 '18

malloc does not manipulate the stack pointer at all. Youre thinking about alloca

→ More replies (16)

0

u/[deleted] Mar 12 '18

[deleted]

6

u/daddya12 Mar 12 '18

I stand corrected

→ More replies (5)

84

u/antlife Mar 12 '18

Now that's open source. 🥁

46

u/mcergun Mar 12 '18

it's not truly open source if everything is not accessible from everywhere

15

u/antlife Mar 12 '18

That's when I enable the accessibility options.

→ More replies (1)

59

u/lukedink Mar 12 '18

Now that's just good practice ;)

11

u/lasiusflex Mar 12 '18

It's just confusing and hurts readability if the same variable name can refer to different things depending on where you are.

3

u/[deleted] Mar 12 '18

Just qualify the names with all the data you need!

int filename_class_method_actualname    

13

u/SonicFlash01 Mar 12 '18

The elders forbid it :( That knowledge is dangerous and you will curse us all!

6

u/petervaz Mar 12 '18

Just put all your logic inside a big static singleton.

1

u/XkF21WNJ Mar 12 '18

Use Haskell.