Page 1 of 1

study, study, study....PLEASE HELP!

Posted: Thu Mar 04, 2004 8:36 pm
by Uncle B
Hello again, good evening/morning/afternoon to you all,
using purebasic for a few months now, i finally got into the more difficult programming, so I started to study examples instead of copying the helpfile. a few days ago I found this piece of code on purearea and have been studying it for the last few evenings in a row.

beeing a rookie like me I did learn a lot from it, like how linkedlists work and stuff like that, but this particular piece of code doesn't get to me.

Code: Select all

;-Unpack
;Gepackte Datei aussuchen und wieder entpacken: 
NewList DateienEntpacken.s() ;Liste zum Entpacken erstellen 
Pfad$ = "C:\" 

;Auswahlfenster für die gepackte Datei 
PackDatei$ = OpenFileRequester("Dateien auswählen", Pfad$, "Gepackte Dateien (*.pac)|*.pac", 0) 
If OpenPack(PackDatei$)                                 ;Gepackte Datei öffnen. 
  *SpeicherAdresse = NextPackFile()                     ;Die erste Datei in eine Speicheadresse schreiben. 
  Groesse = PackFileSize()                              ;Die Groesse der Datei feststellen. 
  ;Die Datei auslesen lassen, damit man die Namen der gepackten Dateien erhält und in die Liste schreiben. 
  For Schleife = 1 To Groesse                            
    String$ = PeekS(*SpeicherAdresse, Groesse) 
    Position = FindString(String$, Chr(13), Schleife) 
    AddElement(DateienEntpacken()) 
    Laenge = Position - Schleife 
    DateienEntpacken() = Mid(String$, Schleife, Laenge) 
    Schleife = Schleife + Laenge + 1 
  Next Schleife    
Else 
  End 
EndIf 


now can someone please explain me what is happening behind the scenes here...

e.g.
- what does the "*" mean (*GepackteDatei), think it has something to do whith the memory, but i'm not sure.
- What is happening in the part with the PeekS thing and all that stuff. (The helpfile tells me that i should stay out of there and, believe me, i would if it wasn't nescessary).

the orriginal piece of code at the codearchief is "Files_Pack&UnPack.pb", I also found another one that looked somewhat eazier but all of the comments were in frensh, really can't make sence out of that language, german is allready on the edge..., that one was named "PackUnpack_with-Filenames.pb" by the way...

well i hope i made my point clear here, thanks in advance,

your faithfull student, Bart
:roll:

Posted: Thu Mar 04, 2004 9:40 pm
by LarsG
don't let the "*" fool you.. it hasn't got any special function...
we normally just use them to underline that the variable is a pointer
(it contains a memory address to something else, usually given by the "@" sign..)

one thing to note though: "*my_var" is NOT the same variable as "my_var"..
just thought I'd let you know, so you don't go wondering about that...

Posted: Thu Mar 04, 2004 11:55 pm
by blueznl
lars, not entirely true, when dealing with structs the * has some effect...

Posted: Fri Mar 05, 2004 9:26 am
by LarsG
blueznl wrote:lars, not entirely true, when dealing with structs the * has some effect...
I was trying not to confuse the guy!! :P

Posted: Fri Mar 05, 2004 10:26 am
by freedimension
LarsG wrote:
blueznl wrote:lars, not entirely true, when dealing with structs the * has some effect...
I was trying not to confuse the guy!! :P
Now you did :twisted:

Posted: Fri Mar 05, 2004 10:32 am
by LarsG
freedimension wrote:
LarsG wrote:
blueznl wrote:lars, not entirely true, when dealing with structs the * has some effect...
I was trying not to confuse the guy!! :P
Now you did :twisted:
I'm evil, ain't I?!? :twisted:

Posted: Fri Mar 05, 2004 10:57 am
by Fred
When you declare a variable with an '*', it's a pointer, which means it will be always the size of the CPU address mode (4 bytes on 32 bits CPU and 8 bytes on 64 bits one for example). When you attach a structure to a pointer (for example *MyPoint.Point) it allows to access any memory address in a structured way. For example:

Code: Select all

   Point1.Point
   Point2.Point
  *CurrentPoint.Point = @Point1
  *CurrentPoint\x = 10 ; 10 is affected to Point1
  *CurrentPoint.Point = @Point2
  *CurrentPoint\x = 10 ; 10 is affected to Point2
I hope it will help a bit :)

Posted: Fri Mar 05, 2004 11:56 am
by Uncle B
Well thanks for not confusing me, and for the replies so far, time to study again.. :D

Posted: Fri Mar 05, 2004 1:58 pm
by blueznl
jo uncle, on my website there's a little sample proggy that shows the difference of structs with real pointers and regular vars