Used Symbols

Just starting out? Need help? Post your questions and find answers here.
Mij
New User
New User
Posts: 6
Joined: Tue Jan 10, 2006 9:02 pm
Location: Holland

Used Symbols

Post by Mij »

Hi there,

Maybe a stupid question, but i wonder.

Why do a lot of programmers use the following symbols and what do they intend

Example:

Code: Select all

PokeB (@wsaversion + 1, low) ; ... and minor version number into high byte 
    If WSAStartup_ (wsaversion, wsa.WSAData) = #NOERROR ; Try to access Windows sockets stuff... 
      *host.HOSTENTSTRU = gethostbyname_ (computer$) ; Get host information for named computer... 
      If *host <> #Null 
        ip = PeekL(PeekL (*host\h_list)) 
        ips$ = PeekS (inet_ntoa_ (PeekL(PeekL (*host\h_list)))) ;

The @ symbol and the * i don't see what they do

Anyone who wants to explane ?


I would be gratefull


Dyon :?: :arrow:
Bonne_den_kule
Addict
Addict
Posts: 841
Joined: Mon Jun 07, 2004 7:10 pm

Post by Bonne_den_kule »

LuCiFeR[SD]
666
666
Posts: 1033
Joined: Mon Sep 01, 2003 2:33 pm

Post by LuCiFeR[SD] »

may I recomend reading "Pointers and memory access" in the manual :)
Pointers and memory access

Pointers

To use a pointer, put * before the variable name. A pointer is a long variable which stores an address. It is generally associated with a structured type. So, you can access the structure via the pointer.
Example:

*MyScreen.Screen = OpenScreen(0,320,200,8,0)
mouseX = *MyScreen\MouseX ; Assuming than the Screen structure contains a MouseX field

There are only three valid methods to set the value of a pointer:
- Get the result from a function (as shown in the above example)
- Copy the value from another pointer
- Find the address of a variable, procedure or label (as shown below)

Note: Other than in C/C++ in PureBasic the * is always part of the variable name. Therefore *ptr and ptr are two different variables.
Addresses of variables

To find the address of a variable in your code, you use the at symbol (@). A common reason for using this is when you want to pass a structured type variable to a procedure. You must pass a pointer to this variable as you cannot pass structured variables directly.
Example:

Structure astruct
a.w
b.l
c.w
EndStructure

Procedure SetB(*myptr.astruct)
*myptr\b = 69
EndProcedure

Define.astruct myvar

SetB(@myvar)

Debug myvar\b

Addresses of procedures

For advanced programmers. The most common reason to get the address of a procedure is when dealing with the OS at a low-level. Some OSes allow you to specify callback or hook functions (for some operations) which get called by the OS and allows the programmer to extend the ability of the OS routine. The address of a procedure is found in a similar way to variables.
Example:

Procedure WindowCB(WindowID.l, Message.l, wParam.l, lParam.l)
; This is where the processing of your callback procedure would be performed
EndProcedure

; A special callback for the Windows OS allowing you to process window events
SetWindowCallback( @WindowCB() )

Addresses of labels

It can also be useful to find the address of labels in your code. This can be because you want to access the code or data stored at that label, or any other good reason you can think of. To find the address of a label, you put a question mark (?) in front of the label name.
Example:

Debug "Size of data file = " + Str(?endofmydata - ?mydata)

DataSection
mydata:
IncludeBinary "somefile.bin"
endofmydata:
Mij
New User
New User
Posts: 6
Joined: Tue Jan 10, 2006 9:02 pm
Location: Holland

OK

Post by Mij »

Well ,

i allready mentiond that it was a stupid question, i looked arround in the help, butt didn't find any relation.


Thanks for Pointing in the right direction
Post Reply