Compiler error (or maybe compiler problem?!) 
Author Message
 Compiler error (or maybe compiler problem?!)

I have a function:
F(byRef param as Type)

and I have a function:
G(byRef param as Type)

When I call G within F with the parameter passed by F as in the
followig example:
Sub F(param as Type)
    G(param)
End sub

then I get a compiler error saying "Reference parameters can only be
local variables".
I am really surprised!!!
Why do I have such an error? I should not..., no?
I looks like an horrible limitation of the compiler..., no?
Is there a way to bypass this problem (still with the advantage of the
byRef possiblities)?

Thanks a lot!



Sun, 17 Oct 2004 04:21:46 GMT  
 Compiler error (or maybe compiler problem?!)

Quote:
> then I get a compiler error saying "Reference parameters can only be
> local variables".

Yep, that's what it is.

Quote:
> I looks like a horrible limitation of the compiler..., no?

Horrible? Try Windows XP.

Seriously: I agree, it is a limitation. However, there's an easy workaround:

- Dim your parameters as local variables
- assign your globals/properties/whatever to them
- pass your locally dimmed variables as "byref"-parameters

Or even better: re-consider your design.

Why not creating a class? Defining properties allows for assignment instead
of passing parameters. Calling methods and let them act on their own
properties does all the rest AND allows for more than one result to be,
well, not "returned", but accessible. Give it a try.

Cheers,

Knut



Sun, 17 Oct 2004 05:57:19 GMT  
 Compiler error (or maybe compiler problem?!)
also if for the function Type is an object of somesort, (i do believe)
the byref is redundant since that's how all objects are passed anyways

otherwise stick to the redesign method... in most cases when i get that
error, it generally means what i should do is create add a flag
arguement to it.
in this case
F(byRef param as type, flag as boolean)
//do whatever g does
if flag then
   //do whatever else F additionally here does here
end if

but nog , generally points to some sort of bad design planning. And
trust me, it's better to solve bad design as soon as possible or the
dreaded complete recode becomes necessary (which is what i'm caught in
now)
Good luck



Sun, 17 Oct 2004 07:35:10 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. gnat304 Daylight Saving Time problem (was: compiler errors in GNAT 304a (win95))

2. HINT: Compiler error-handling has problems

3. configure: error: installation or configuration problem: C compiler cannot create executables

4. Compiling TK : configure: error: installation or configuration problem: C compiler cannot create executables

5. Problems parsing f90 compiler errors w/ emacs

6. Problem: Compiler Error

7. Compiler Compilers

8. (none)Compiler-Compiler

9. Marcel's compiler /was Forth compiler technology

10. Compiler warning suggestion, Smalltalk compiler in 5.0?

11. Updated Win32 Compiler Comparisons (including results for Salford's .NET compiler)

12. Ada Compiler-Compiler

 

 
Powered by phpBB® Forum Software