IonicWind Software

Aurora Compiler => General Discussion => Topic started by: Ionic Wind Support Team on December 10, 2005, 08:37:32 PM

Title: Scope resolution
Post by: Ionic Wind Support Team on December 10, 2005, 08:37:32 PM
Been working on scope resolution this evening.  When a class method has the same name as an imported function or external subroutine you have to tell the compiler which function to use when your within a class method.

So keeping with C like syntax I've used the double colon.  Illustrated in this code snippet, the code for GetClientRect from the window class.


DECLARE IMPORT,GetClientRect(hwnd as int,lpRect as RECT),INT;
window::GetClientRect(),RECT
{
RECT rc;
rc.left = 0;rc.top = 0;rc.right = 0;rc.bottom = 0;
if(m_hWnd)
::GetClientRect(m_hWnd,rc);
return rc;
}


In the code above we have a name conflict.  GetClientRect exists as both an imported DLL function and the class method.  Using a '::' in front of a function name tells the compiler you want global scope, and not local.

Without it you would get a 'wrong number of parameters' error since the class method takes precedence over the global imported funciton.

Just noting it here for future reference.

Title: Re: Scope resolution
Post by: Parker on December 11, 2005, 09:13:29 AM
Just wondering, is there going to be a way to pass RECT structures to a function by doing something like this:
SomeFunction(RECT{0, 0, 500, 500});
Title: Re: Scope resolution
Post by: Ionic Wind Support Team on December 11, 2005, 09:32:45 AM
Probably not right away.  Requires a lot of memory management for the temporary struct.

However once class constructors can accept parameters you could have a rect class

SomeFunction(CRect(0,0,100,100))

Which is the same thing.

Paul.
Title: Re: Scope resolution
Post by: Parker on December 11, 2005, 09:39:04 AM
Cool, glad to know it'll work that way, so for now just a request in the future for the ability to pass structures like that. Thanks.
Title: Re: Scope resolution
Post by: GWS on December 22, 2005, 06:26:08 AM
Will there be 'block' scoping as in C++ .. I've been reading againÂÃ,  ::) and it's a new one on me.

Also, I triedÂÃ,  ÂÃ, int x = 5; and it doesn't compile.ÂÃ,  Will this form of define and initialise be possible?

Graham :)
Title: Re: Scope resolution
Post by: Ionic Wind Support Team on December 22, 2005, 06:55:47 AM
Graham,
No to the block resolution.  Yes to the initialization. ;)

I've always considered block scoping more of a C++ trick than a feature.  In a subroutine the variable will always be located on the stack regardless of wether or not the compiler lets you access it.  It is also very confusing to new programmers, not to mention prone to causing bugs.

For example.


sub MySub()
{
int z,x;
    for(x = 0;x < 7;x++)
    {
       int z; // only accessable during the for loop
       z = x+100;
    }
    writlen(str$(z)); // uses the 'z' at the scope of the subroutine
}



Title: Re: Scope resolution
Post by: Zen on December 22, 2005, 07:33:12 AM
This is good news. I like the idea of being able to define and initialize variables. Ive had many occasions when i have had about 50 lines of code in IBasic. 50 to define and 50 to initialize. I know you can do both on one line but i think im one of those code tidy freaks. lol

Lewis
Title: Re: Scope resolution
Post by: ThadMiller on December 22, 2005, 07:35:50 AM
Quote from: Ionic Wizard on December 22, 2005, 06:55:47 AM
I've always considered block scoping more of a C++ trick than a feature.

But .Net also does block scoping, so it MUST be the right thing to do!  ::)

(sorry, couldn't resist  ;) )
Title: Re: Scope resolution
Post by: Parker on December 22, 2005, 11:40:11 AM
I've seen it in freebasic:
scope
dim x as integer = 1 ' only available in the scope block
print x
end scope
print x ' will give an error since x doesn't exist


I wasn't aware that it existed in C++, although I've never tried to use it, it's probably just a better idea to use standard variables since that would get confusing though, I agree with Paul. Although having it as a feature never hurts if Paul wants to change his mind, or do something like scope{ ... }  ;)
Title: Re: Scope resolution
Post by: srod on December 22, 2005, 03:29:43 PM
Sorry for drifting off topic a little and forgive the dumb question!

Paul, in the import statement below
DECLARE IMPORT,GetClientRect(hwnd as int,lpRect as RECT),INT;

How is it that we are not required to name the underlying dll file? Am I right in assuming that Aurora automatically links to the common system dll's?






Title: Re: Scope resolution
Post by: Ionic Wind Support Team on December 22, 2005, 03:32:35 PM
It works just like it did in Pro.  There are import libraries in your 'libs' directory and a few of them are automatically linked against.  Such as kernel32.lib, user32.lib and gdi32.lib.

If you were to use a third party DLL you would need to create the import library with the tools menu and then include it with your project using a #use statement.

#use "somedll.lib"

Title: Re: Scope resolution
Post by: srod on December 22, 2005, 03:41:02 PM
Thanks for the reply.  To be honest, I never really got to grips with IB pro, mainly because I was already very comfortable with the basic language I was already using and saw no real need to switch when both l anguages offered more or less the same functionality.

Aurora is a different kettle of fish, however, in that I think this is looking to be the perfect way into OO, the perfect complement to my existing development language.

I will purchase a licence when I get back to my broadband connection, after xmas.