[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] gets strengen



Sune <sslug@sslug> writes:

> Her er fx. endnu én som er af en anden mening:
> http://www-ee.eng.hawaii.edu/~tep/EE150/book/chap7/subsection2.1.3.2.html
> 
> "As we have seen, when we declare an array, a contiguous block of memory is allocated for the
> cells of the array and a pointer cell (of the appropriate type) is also allocated and initialized
> to point to the first cell of the array. This pointer cell is given the name of the array. When

Ovenstående er noget vrøvl. Der bliver altså ikke allokeret en pointer
når du allokerer en array i nogle compilere jeg kender.

Her er et faktisk eksempel:

Et lille C program der bruger en array or en pointer.

int main() {
    char buf[4];
    char *buf2 = buf;

    buf[0] = 1;
    buf2[0] = 1;
    
}


. og tilgår noget hukommelse via dem. Hvordan ser koden så ud?

Når man tilgår arrayen:


    buf[0] = 1;
 80483ec:       c6 45 fc 01             movb   $0x1,0xfffffffc(%ebp)

Bliver der flyttet en byte direkte til arrayen hvis adresse (i forhold
til stakken) vi kender. Der er ingen pointer involveret her.


Men når vil tilgår dataene via pointeren:

    buf2[0] = 1;
 80483f0:       8b 45 f8                mov    0xfffffff8(%ebp),%eax
 80483f3:       c6 00 01                movb   $0x1,(%eax)


bliver pointerens værdi først hentet ind i et register og adresseret
videre derfra.



-- 
===============================================================
<sslug@sslug>     Herlev, Denmark     Software Designer
<URL:http://www.andreasen.org/>   <*>   Eicon Networks Research
===============================================================



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:09 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *