Global variables are stored in data, dynamically allocated variables are stored in heap, etc. Where are functions (such as main, other functions in main.c, printf, etc) stored? Is it in the code segment?
-
2Research makes you a better programmer.– GunnerCommented Dec 10, 2014 at 2:57
-
1On the stack, yo. hence why recursion can eat up your whole stack, thus causing a stack overflow...– GillespieCommented Dec 10, 2014 at 2:58
-
1Google is your friend.– pmvermaCommented Dec 10, 2014 at 2:59
-
Side note: you'll save yourself a lot of grief if you stop thinking of C and C++ as the same language.– Andrew BarberCommented Dec 10, 2014 at 3:00
-
Neither C nor C++ have any concept of segments, this is an implementation detail of the tool chain and there is no standard that specifies where they are stored.– Captain ObvliousCommented Dec 10, 2014 at 3:01
|
Show 2 more comments
1 Answer
This is not a C or C++ question. Neither of those ISO standards mandate anything like how different things are allocated to memory segments.
In fact, the whole idea of segments is irrelevant to the standards since they dictate the behaviour of a C or C++ "virtual machine" - they tend to dictate behaviour rather than how the behaviour is achieved.
However, if you're in an implementation that has a code segment, that's the most likely place where code would be stored :-)