Liste des Groupes | Revenir à cl c |
In my compiler (BGBCC), such an internal pointer exists for arrays and structures in the local stack frame.The C standard does not require a stack or say how local data is implemented, it just gives rules for the scope and lifetime of locals. However, I would be surprised and shocked to find a compiler I was using allocate local data on the heap in some manner. If I have an array as local data, it is with the expectation that it is allocated and freed trivially (an add or subtract to the stack pointer, typically combined with any other stack frame). If I want something on the heap, I will use malloc and put it on the heap.
No separate pointer exists inside of things like structs, where, as can be noted, the array exists at a fixed size and location.
So, eg:
void Foo()
{
int a[100];
...
}
There is both the space for 100 integers reserved in the stack frame, and a variable 'a' which exists as an implicit pointer to that location.
But, say:
void Foo()
{
int a[8192];
...
}
There is no space reserved on the stack, and the array is instead allocated dynamically (from the heap). In this case, the "a" variable exists as a pointer to that location in memory.
Similar treatment also applies to structs.
Les messages affichés proviennent d'usenet.