Syntax for "Function" and "Global" keywords.

BlitzMax Forums/BlitzMax Beginners Area/Syntax for "Function" and "Global" keywords.

AarbronBeast(Posted 2009) [#1]
Hi all.

In researching modules and, specifically, the use of the "Extern" keyword, I came across some undocumented syntax. Can someone shed some light?

The BlitzMax docs speaks of the following syntax for the "Function" and "Global" keywords, which is fine:

Extern
Function MyExternFunction(aParam)
Function MyExternFunction()="MyExternFunctionAlias"
Global MyGlobalVar="HELLO"
End Extern

But what does these mean?

Extern
Function MyExternFunction(aParam)=AnotherFunction(AParam)
Global MyExternFunction()="StringLiteral"
End Extern

A function with another function as an alias? Using Global to identify a function? What gives here?

Thanks.


grable(Posted 2009) [#2]
The Global one still uses a symbol alias, its still a global just containing a function pointer.

The other one, im not too sure. bmx complains about "Unrecognized intermediate expression" no matter what i try :(


AarbronBeast(Posted 2009) [#3]
Hi grable.

Thanks for your reply. About that Global example, I don't think I fully understand. Here is some code:

Global b1:Byte = 100
Global b2:Byte = 200
Global b3:Byte = 300

Function MyFunc:Byte Ptr(name$)
If (name$ = "Global1") Then Return Varptr b1
If (name$ = "Global2") Then Return Varptr b2
If (name$ = "Global3") Then Return Varptr b3
End Function

Global Global1(a$) = MyFunc("Global1")

Now, how would I use that Global?


grable(Posted 2009) [#4]
It seems your confusing pointers with function pointers.

Im assuming this is the behaviour your after?
Global b1:Byte = 100
Global b2:Byte = 200
Global b3:Byte = 300

Function MyFunc:Byte Ptr( name$)
If (name$ = "Global1") Then Return Varptr b1
If (name$ = "Global2") Then Return Varptr b2
If (name$ = "Global3") Then Return Varptr b3
End Function

Global Global1:Byte Ptr = MyFunc("Global1")
Print "Global1=" + Global1[0]


With parentheses, its a function AND a variable ;)
So you could do something like this:
Global myprint( s:String) = Print
myprint( "hello")


But wasnt your original question about Externs??
In which case the same holds true, except the identifiers must be defined elsewhere and imported.


AarbronBeast(Posted 2009) [#5]
Hi grable.

Yes, my original question was about Extern, you are correct. I was only providing an example so I could understand the usage of the resulting Global, which isn't really affected by whether it was defined locally or externally.

I understand both of those concepts just fine... but what I want to understand is the concept of a Global having brackets on both sides of the equals sign. As in this code here:

Global alcOpenDevice( devicename$z )=P("alcOpenDevice")


This particular example doesn't have to do with Extern though.

(By the way, what are the tags to use to get the code samples appearing in the black+green text on this forum?)

Thanks!


_Skully(Posted 2009) [#6]
{code} {/code} but change the {}'s to []'s

or click the forum codes link below


AarbronBeast(Posted 2009) [#7]
Thanks! I thought I tried that, but I think I used uppercase. Is it case sensitive?


_Skully(Posted 2009) [#8]
[CODE]Yes[/CODE]