BASIC

Author Topic: Better Expression As A Parameter Handling  (Read 8027 times)

Offline kanonet

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1142
    • View Profile
    • My GLBasic code archiv
Re: Better Expression As A Parameter Handling
« Reply #15 on: 2012-Sep-24 »
The string problems that i described in an other Thread are  gone with this hotfix. :good:
But bigsofty's problem from this thread still exist.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2556
    • View Profile
Re: Better Expression As A Parameter Handling
« Reply #16 on: 2012-Sep-24 »
Yes, the DIMDATA bug has neen squashed but the type reference problems that were described at the beginning of this thread still exists.  :(

Code: GLBasic [Select]
*** Configuration: WIN32 ***
precompiling:
GPC - GLBasic Precompiler V.10.079 SN:2e101695 - 3D, NET
Wordcount:10 commands
compiling:
C:\Users\Dad\AppData\Local\Temp\glbasic\gpc_temp0.cpp: In function `DGInt __GLBASIC__::caller()':
C:\Users\Dad\AppData\Local\Temp\glbasic\gpc_temp0.cpp:109: error: invalid initialization of non-const reference of type '__GLBASIC__::TVec3&' from a temporary of type '__GLBASIC__::TVec3'
C:\Users\Dad\AppData\Local\Temp\glbasic\gpc_temp.h:10: error: in passing argument 1 of `DGInt __GLBASIC__::vecfunc(__GLBASIC__::TVec3&)'
*** FATAL ERROR - Please post this output in the forum
_______________________________________
*** Finished ***
Elapsed: 1.1 sec. Time: 22:49
Build: 0 succeeded.
*** 1 FAILED ***
Cheers,

Ian.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration.”
(E. W. Dijkstra)

MrTAToad

  • Guest
Re: Better Expression As A Parameter Handling
« Reply #17 on: 2012-Sep-25 »
We will give it a test :)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10665
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Better Expression As A Parameter Handling
« Reply #18 on: 2012-Sep-25 »
Oh dear. I think it's because of my emergency return value when you forget to return anything.
I'll keep digging...

[edit]
oh no!!!
Code: GLBasic [Select]
Tvec foo()
{
   Tvec; v; return v;
}
void bar(Tvec& v)
{
}
int main()
{
   bar(foo() );
}
 

In C++ an "rvalue" (the return thing of a function e.g.) cannot be passed as a reference to a function. It might be passed as a const reference, but then it would not allow you to modify the object passed.

So... You would need a temporary object to pass to this function. The only thing I could think of would be an BYVAL keyword for arguments.


« Last Edit: 2012-Sep-25 by Kitty Hello »

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2556
    • View Profile
Re: Better Expression As A Parameter Handling
« Reply #19 on: 2012-Sep-26 »
This would be fine Gernot, Delphi and C# have keywords for variables that are passed as parameters by reference. Which would be fine for me too.  ;)
Cheers,

Ian.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration.”
(E. W. Dijkstra)

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2556
    • View Profile
Re: Better Expression As A Parameter Handling
« Reply #20 on: 2012-Sep-30 »
Here's a rather strange thing, it may be related it may be not.

This function...

Code: GLBasic [Select]
        // Convert a 2D x,y to 3D vec
FUNCTION v2D23D AS TVec3: vec2D AS TVec2, z#=0
        LOCAL vec3D AS TVec3
        INLINE
        return vec3D.SetUp(vec2D.x-screenCentre.x,-vec2D.y+screenCentre.y,z);
        ENDINLINE
        RETURN vec3D.SetUp(vec2D.x-screenCentre.x,-vec2D.y+screenCentre.y,z)
        ENDFUNCTION

Actually creates the same return C code ("return vec3D.SetUp(vec2D.x-screenCentre.x,-vec2D.y+screenCentre.y,z);")...

Code: GLBasic [Select]
// Convert a 2D x,y to 3D vec.
// ------------------------ //
TVec3 v2D23D(TVec2& vec2D, DGInt z)
{
   __PPRegisterFunction
  #undef __FKT
  #define __FKT __l_dbg_cont
  __VAR_CONTAINER __FKT;
ARGS_VAR(TVec2, vec2D);
ARGS_VAR(DGInt, z);

                                                                                                #undef __GLBNO__
                                                                                                #define __GLBNO__ 258

                                                                                                #undef __GLBNO__
                                                                                                #define __GLBNO__ 259
                                                                                                ON_DEBUG(12,259);
REGISTER_VAR(TVec3, vec3D);

                                                                                                #undef __GLBNO__
                                                                                                #define __GLBNO__ 260
                                                                                                ON_DEBUG(12,260);

/* ---- INLINE ---- */

return vec3D.SetUp(vec2D.x-screenCentre.x,-vec2D.y+screenCentre.y,z);


/* ---- ENDINLINE ---- */

                                                                                                #undef __GLBNO__
                                                                                                #define __GLBNO__ 262

                                                                                                #undef __GLBNO__
                                                                                                #define __GLBNO__ 263
                                                                                                ON_DEBUG(12,263);
return vec3D.SetUp(vec2D.x-screenCentre.x,-vec2D.y+screenCentre.y,z);

                                                                                                #undef __GLBNO__
                                                                                                #define __GLBNO__ 264

                                                                                                #undef __GLBNO__
                                                                                                #define __GLBNO__ 265
                                                                                                ON_DEBUG(12,265);
return TVec3();
}

Yet, the pre-compiler throws an error ""misc.gbas"(316) error : GPC0007 wrong argument type :" for the GLBasic RETURN line?

If I remark the GLBasic RETURN line out it works as expected, using the inline C for the return value as expected.


Oh, here is the TYPE that is called.

Code: GLBasic [Select]
TYPE TVec3

        x#
        y#
        z#
        w# = 1

        FUNCTION SetUp AS TVec3: x#, y#, z#
                self.x#=x#; self.y#=y#; self.z#=z#
                RETURN self
                ENDFUNCTION

ENDTYPE
 
« Last Edit: 2012-Sep-30 by bigsofty »
Cheers,

Ian.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration.”
(E. W. Dijkstra)

jestermon

  • Guest
Re: Better Expression As A Parameter Handling
« Reply #21 on: 2012-Sep-30 »
I may be going a bit overboard with my enthusiasm, but heck, it's not everyday that small code snippit posts tell me more than weeks of searching. So again, my thanks for showing a "returnable" self - in full working context in GLB.
I'm still not used to this level of coding in any version of the Basic language.

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2556
    • View Profile
Re: Better Expression As A Parameter Handling
« Reply #22 on: 2012-Sep-30 »
You very welcome Jestermon. I think maybe the description of GLBs advanced types needs more documentation in the manual to help people digest this, extremely usefull, aspect of the GLBasic language?
Cheers,

Ian.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration.”
(E. W. Dijkstra)