PureBASIC Procedures : Procedure() and new one Function()
PureBASIC Procedures : Procedure() and new one Function()
Hey Fred
I want to like to see that there is an different of the procedures that return an value or without an value
Syntax of the statement :
DECLARE FUNCTION (BYVAL / BYREF a AS INTEGER) AS INTEGER[()]
- The keywords BYVAL => Parameters By value passed
- The keywords BYREF => Parameters By references passed
[PRIVATE|PUBLIC|LOCAL|STATIC] FUNCTION <function_name>([BYVAL | BYREF] AS <datatype|array()|struct|pointer>) AS <Return_data_type>[()]
- Scope: PRIVATE | PUBLIC | LOCAL | STATIC
RETURN (value or reference)
END FUNCTION
I hope that this added in the next update/upgrade of PowerBASIC
Kind regards
Stephane
I want to like to see that there is an different of the procedures that return an value or without an value
Syntax of the statement :
DECLARE FUNCTION (BYVAL / BYREF a AS INTEGER) AS INTEGER[()]
- The keywords BYVAL => Parameters By value passed
- The keywords BYREF => Parameters By references passed
[PRIVATE|PUBLIC|LOCAL|STATIC] FUNCTION <function_name>([BYVAL | BYREF] AS <datatype|array()|struct|pointer>) AS <Return_data_type>[()]
- Scope: PRIVATE | PUBLIC | LOCAL | STATIC
RETURN (value or reference)
END FUNCTION
I hope that this added in the next update/upgrade of PowerBASIC
Kind regards
Stephane
Re: PureBASIC Procedures : Procedure() and new one Function(
idStefke wrote:Hey Fred
I hope that this added in the next update/upgrade of PowerBASIC
Kind regards
Stephane

I don't know for powerbasic, but I don't find this necessary for PureBasic. You can already define the return type:
Long is the default, if no type is declared. If you don't need the return value, just don't use it. VB just complicates things unnecessarily.
Code: Select all
Procedure.l Whatever(mylong.l, mystring.s)
Procedure.f Whatever(mylong.l, mystring.s)
Procedure.w Whatever(mylong.l, mystring.s)
Procedure.b Whatever(mylong.l, mystring.s)
Procedure.s Whatever(mylong.l, mystring.s)
El_Choni
- tinman
- PureBasic Expert
- Posts: 1102
- Joined: Sat Apr 26, 2003 4:56 pm
- Location: Level 5 of Robot Hell
- Contact:
Edit: removed my incorrect ramblings, so as to not cause confusion.
Last edited by tinman on Sat Jun 07, 2003 10:52 pm, edited 1 time in total.
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
(WinXPhSP3 PB5.20b14)
By default a procedure returns a long, no need to specify a type
Code: Select all
Procedure JustSomething()
ProcedureReturn 123
EndProcedure
Debug JustSomething()
Powerbasic does have some nice things I'd like to see in Pure (such as Static variables), but the current Pure is fine for what I use it for.
On a related note, though, I'm used to using 'Function' instead of 'Procedure' and thought it would be cool if 'Function' and 'Procedure' could be used interchangeably for the same thing. This way, old code would not be affected and those users would be able to continue to use 'Procedure' if they like.
Russell
On a related note, though, I'm used to using 'Function' instead of 'Procedure' and thought it would be cool if 'Function' and 'Procedure' could be used interchangeably for the same thing. This way, old code would not be affected and those users would be able to continue to use 'Procedure' if they like.
Russell
*** Diapers and politicians need to be changed...for the same reason! ***
*** Make every vote equal: Abolish the Electoral College ***
*** www.au.org ***
*** Make every vote equal: Abolish the Electoral College ***
*** www.au.org ***
Re: PureBASIC Procedures : Procedure() and new one Function(
> I hope that this added in the next update/upgrade of PowerBASIC
This is the PureBasic forum, NOT PowerBasic forum.
This is the PureBasic forum, NOT PowerBasic forum.
A quick little story: I find out about Pure Basic by accident when I was doing a search for "PB graphics library" for PowerBasic (PowerBasic is also known by its initials 'PB'). Maybe there was some similar accidental finding in this case?
Russell
Russell
*** Diapers and politicians need to be changed...for the same reason! ***
*** Make every vote equal: Abolish the Electoral College ***
*** www.au.org ***
*** Make every vote equal: Abolish the Electoral College ***
*** www.au.org ***
Regarding ByVal and ByRef.
You don't need byVal and ByRef.
If you are passing a String, then you pass a string. If you are passing a pointer, then you pass a long.
Pointers cause terrible confusion in other languages because they are always trying to pretend that they are not pointers.
In C they try to treat a pointer like it is really the thing it is pointing to. So you have a pointer to a String, but you try to treat it like it really is a string. This causes so much confusion that they had to invent Hungarian Notation to tell you its really a long pointer to a string (lpsz). Then their listings looks like Hungarian (hence the name)
Its so much easier to just admit that a pointer is a pointer. It is a numerical value that points to a memory location.
Then, when you want to use that pointer you call a function that accepts that numerical value, like the Peek functions or CallFunctionFast.
Easy to understand, easy to use.
You don't need byVal and ByRef.
If you are passing a String, then you pass a string. If you are passing a pointer, then you pass a long.
Pointers cause terrible confusion in other languages because they are always trying to pretend that they are not pointers.
In C they try to treat a pointer like it is really the thing it is pointing to. So you have a pointer to a String, but you try to treat it like it really is a string. This causes so much confusion that they had to invent Hungarian Notation to tell you its really a long pointer to a string (lpsz). Then their listings looks like Hungarian (hence the name)
Its so much easier to just admit that a pointer is a pointer. It is a numerical value that points to a memory location.
Then, when you want to use that pointer you call a function that accepts that numerical value, like the Peek functions or CallFunctionFast.
Easy to understand, easy to use.
I know what you mean, GedB. They try to make pointers 'easier to understand', but in the process make it more complicated. All we need to know is that a pointer is a long value that represents an address of something. It should be up to us to name our variables so that we remember, for example, that 'Text' is a pointer to some text ('pText'). Forgetting to do so can cause problems later when you look at someone else's code and are trying to figure out what is happening.
Pointers that point to a sequence of pointers can REALLY be a head scratcher, but can really speed certain things up if you can wrap your brain around the idea!
Nobody can make pointers more complicated to understand than C++, though... Well maybe 'forth' (Even asm has an easier concept when it comes to pointers).
Russell
Russell
Pointers that point to a sequence of pointers can REALLY be a head scratcher, but can really speed certain things up if you can wrap your brain around the idea!

Nobody can make pointers more complicated to understand than C++, though... Well maybe 'forth' (Even asm has an easier concept when it comes to pointers).
Russell
Russell
*** Diapers and politicians need to be changed...for the same reason! ***
*** Make every vote equal: Abolish the Electoral College ***
*** www.au.org ***
*** Make every vote equal: Abolish the Electoral College ***
*** www.au.org ***
-
- Enthusiast
- Posts: 499
- Joined: Wed Sep 17, 2003 9:17 pm
- Location: Southern California
- Contact:
pointers
I dun think they're a head scratcher MOST of the time...
you can do some fun stuff when the compiler knows it's pointer and not just a long variable...
example:
[/i]

you can do some fun stuff when the compiler knows it's pointer and not just a long variable...
example:
Code: Select all
Structure PlayerType
*TargetBaddie.BaddieType
name.s
EndStructure
Structure BaddieType
*TargetPlayer.PlayerType
name.s
EndStructure
;Create characters
Player.PlayerType
Baddie.BaddieType
;Name them
Player\name="Mario"
Baddie\name="Goomba"
;Set their targets (who's ass they wanna kick)
Player\TargetBaddie=@Baddie
Baddie\TargetPlayer=@Player
;Display some information
Debug "Player Name: "+Player\name
Debug "Baddie Name: "+Baddie\name
Debug "=== Fun Part ==="
Debug Player\name+"'s Target: "+Player\TargetBaddie\name
Debug Baddie\name+"'s Target: "+Baddie\TargetPlayer\name
Debug "=== Fun-er Part ==="
Debug Player\name+"'s Target's Target: "+Player\TargetBaddie\TargetPlayer\name
Debug Baddie\name+"'s Target's Target: "+Baddie\TargetPlayer\TargetBaddie\name
Debug "=== HEHEHE ==="
Debug Player\TargetBaddie\TargetPlayer\TargetBaddie\TargetPlayer\TargetBaddie\TargetPlayer\TargetBaddie\name
-
- Addict
- Posts: 1073
- Joined: Fri Apr 25, 2003 11:13 pm
- Location: Netherlands
- Contact: