I assume that this question is more related to compilation/linkage rather than to the C standard.
Consider the following method for computing stack-size:
#define ORDER(a,b,c) ((a) <= (b) && (b) <= (c))
int global;
int main()
{
int local;
unsigned long long dataAddr = (unsigned long long)&global;
unsigned long long stackAddr = (unsigned long long)&local;
unsigned long long codeAddr = (unsigned long long)main;
if (ORDER(stackAddr,dataAddr,codeAddr) || ORDER(codeAddr,stackAddr,dataAddr))
printf("Stack size is %llu bytes\n",dataAddr-stackAddr);
else if (ORDER(stackAddr,codeAddr,dataAddr) || ORDER(dataAddr,stackAddr,codeAddr))
printf("Stack size is %llu bytes\n",codeAddr-stackAddr);
else
printf("Stack size cannot be computed with this method\n");
return 0;
}
Except for the obvious case in which the stack is located after the code-section and the data-section, what other possible cavities exist in this method?
Is it possible that one or more sections do not start where I'm expecting them to?
Thanks