Confusing Error

Previous topic - Next topic

bigsofty

A type error is reported but the error does no indicate where the error is, instead it points at another subroutine, away from the main file...

"Main Program"...

Code (glbasic) Select
SLL_initialise(10)

// FOR i = 0 TO LEN(deadARR)     // LEN(deadARR) should cause the error but is never reported
// NEXT
SHOWSCREEN



"Sources"...

Code (glbasic) Select
TYPE TdeadArray
length% // set this at intialisation
ENDTYPE


GLOBAL deadARR AS TdeadArray


FUNCTION SLL_initialise: dataArrayDim%
deadARR.length% = dataArrayDim% /// Here is where the error is reported
ENDFUNCTION // SLL_INITIALISE


Removing the remarks in the first file, show the error. Yes, I realise "deadARR" is not an array but instead of the compiler telling me this it complains about another line of code. This was very confusing as the error line it displayed was in a completely different file?!?!

*** Error reported
Code (glbasic) Select
*** Configuration: WIN32 ***
precompiling:
GPC - GLBasic Precompiler V.7.098 SN:2a049f7b - 3D, NET
"libfile.gbas"(15) error : wrong argument type : TYPE  is not declared
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)

Kitty Hello

can you make a single source that indicates the problem?

bigsofty

#2
Merging them both together...

Code (glbasic) Select
TYPE TdeadArray
length% // set this at intialisation
ENDTYPE


GLOBAL deadARR AS TdeadArray



SLL_initialise(10)

FOR i = 0 TO LEN(deadARR)
NEXT
SHOWSCREEN



FUNCTION SLL_initialise: dataArrayDim%
deadARR.length% = dataArrayDim%
ENDFUNCTION // SLL_INITIALISE


produces...

Code (glbasic) Select
GPC - GLBasic Precompiler V.7.098 SN:2a049f7b - 3D, NET
Wordcount:7 commands
compiling:
C:\DOCUME~1\Dad\LOCALS~1\Temp\glbasic\gpc_temp0.cpp: In function `int __GLBASIC__::__MainGameSub_()':
C:\DOCUME~1\Dad\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:33: error: no matching function for call to `LEN(__GLBASIC__::TdeadArray&)'
C:/Program Files/GLBasic/Compiler/platform/Include/glb.h:767: note: candidates are: DGNat __GLBASIC__::LEN(DGInt)
C:/Program Files/GLBasic/Compiler/platform/Include/glb.h:768: note:                 DGNat __GLBASIC__::LEN(DGNat)
C:/Program Files/GLBasic/Compiler/platform/Include/glb.h:769: note:                 DGNat __GLBASIC__::LEN(const __GLBASIC__::DGStr&)
C:/Program Files/GLBasic/Compiler/platform/Include/glb.h:770: note:                 DGNat __GLBASIC__::LEN(const __GLBASIC__::DGIntArray&)
C:/Program Files/GLBasic/Compiler/platform/Include/glb.h:771: note:                 DGNat __GLBASIC__::LEN(const __GLBASIC__::DGNatArray&)
*** FATAL ERROR - Please post this output in the forum
_______________________________________
*** Finished ***
Elapsed: 1.0 sec. Time: 11:48
Build: 0 succeeded.
*** 1 FAILED ***


So this is much closer to what I would expect to see.

As my code is pretty modular, I am sure you can see why the first 'misreporting' error caused so (and will continue to cause) much trouble.

P.S. I modified the first thread to show the problem a little more clearly
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)

Kitty Hello

Aw, bad. The LEN() function takes anything as an argument, but there's no LEN function in GLBasic that takes a type, only type arrays.
Hm. Will be hard to fix. I might implement a template LEN function that returns the size of the type in bytes. :/

bigsofty

#4
Quote from: Kitty Hello on 2009-Oct-26
Aw, bad. The LEN() function takes anything as an argument, but there's no LEN function in GLBasic that takes a type, only type arrays.
Hm. Will be hard to fix. I might implement a template LEN function that returns the size of the type in bytes. :/

Not a problem bud, I don't actually require the length of a type (although that could be handy), the error was a result of me not adding an array reference and then using len (it should have read "LEN(deadARR.availNodesPtrARR[]")).

My type did read...
Code (glbasic) Select

TYPE TdeadArray
availNodesPtrARR%[]
endPTR%
length%
ENDTYPE


I just simplified it to show the preprocessor error.

What happened was, I was typing in the LEN command, got distracted (baby puke emergency! :P), went back, ran a compile and it pointed to an error in the wrong file, which I then, wrongly, proceeded to take the file apart, not knowing that the LEN error was causing a false error report in that file.

So this is more of an preprocessor error, reporting an error in the wrong place.
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)

bigsofty

#5
Another (similar?) error...

Changing the first listing from the top thread...
Code (glbasic) Select
SLL_initialise(10)

//   FOR i = 0 TO LEN(deadARR)     // LEN(deadARR) should cause the error but is never reported
//   NEXT
   SHOWSCREEN 


to...
Code (glbasic) Select
SLL_initialise(10)

INC deadARR.length%
SHOWSCREEN


Causes
Code (glbasic) Select
"int2.gbas"(4) error : wrong argument type : TYPE  is not declared

Changing...
Code (glbasic) Select
INC deadARR.length%

to...
Code (glbasic) Select
INC (deadARR.length%)

allows it to compile without errors?
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)

Kitty Hello

As you see - my precompiler concerning types is not the best :(

I see if I can make it better.