It's been quite some time, I have been programming in C/C++, but some areas still elude me. Perhaps I haven't been reading from well written and authoritative material.
(1) In Linux/Unix, is there a limit on how large user programs can be? Maximum size of stack a program can have? Max amount of memory in a heap a user program can use?
(2) I understand that a C executable has data section, code section & stack section. If the program is getting into many recursive calls, it would need a large amount of stack. Is this stack of predefined size or will it grow as recursion increases. In case of growth, must the address space of program also be dynamically increased? If so, won't that slow down the program?
(3) Similarly, when memory from heap is allocated to program at runtime when the program mallocs, that area of heap would need to be added to address space of program? Thus in this case also, the page table of program needs to be updated. Is my understanding correct?
(4) Why is it that 2 files (which I intend to combine to form single executable) can't have a global variable of same name. It would help to throw some light on what the object files look like.
Addition:
I am reading ISO C99 standard from http://www.open-std.org/jtc1/sc22/wg...docs/n1256.pdf. It says on page 42:
6.2.2 Linkages of identifiers 1 An identifier declared in different scopes or in the same scope more than once can be made to refer to the same object or function by a process called linkage.There are three kinds of linkage: external, internal, and none.
2 In the set of translation units and libraries that constitutes an entire program, each declaration of a particular identifier with external linkage denotes the same object or function. Within one translation unit, each declaration of an identifier with internal linkage denotes the same object or function. Each declaration of an identifier with no linkage denotes a unique entity.
3 If the declaration of a file scope identifier for an object or a function contains the storage-class specifier static,the identifier has internal linkage.
4 For an identifier declared with the storage-class specifier extern in a scope in which a prior declaration of that identifier is visible,if the prior declaration specifies internal or external linkage, the linkage of the identifier at the later declaration is the same as the linkage specified at the prior declaration. If no prior declaration is visible, or if the prior declaration specifies no linkage, then the identifier has external linkage.
5 If the declaration of an identifier for a function has no storage-class specifier,its linkage is determined exactly as if it were declared with the storage-class specifier extern.If the declaration of an identifier for an object has file scope and no storage-class specifier, its linkage is external.
After reading this it looks that if I declare a variable like say int a in 2 source files. then both have external linkage as per rule 5 and 4. and then as per rule 2, both should refer to the same object. Then why does the compiler create problem. Where in the standard it is hinted that we can't declare like this in 2 source files and this should throw compilation error.
Thanks.