Author Topic: Preprocessor to check function parameters  (Read 2440 times)

Offline FutureCow

  • HelpEditor
  • Prof. Inline
  • ******
  • Posts: 680
    • View Profile
I would like the preprocessor to check the right amount of parameters are being passed to functions and display an appropriate error message, rather than getting a somewhat cryptic error from the compiler.

eg. I have a function like follows
Code: GLBasic [Select]
function ProcessTimers: A, B
but call it with ProcessTimers(1234)

I would like an error message like
Quote
"myfile.gbas"(158) error : wrong number of parameters passed to function ProcessTimers

Instead it gives the C code equivalent with DGInt's etc in it. eg :-
Quote
too few arguments to function `DGInt __GLBASIC__::ProcessTimers(DGInt, DGInt)'

Offline FutureCow

  • HelpEditor
  • Prof. Inline
  • ******
  • Posts: 680
    • View Profile
Re: Preprocessor to check function parameters
« Reply #1 on: 2009-May-29 »
More particularly, the compiler errors reference gpc_tempx.cpp and not the actual gbas file, so I've got to go into the cpp file, find the filename of the gbas file from the top, then search through the gbas file until I find (manually) the line with the error.

If it was picked up by the preprocessor I could double click it and go straight to the error and it would be easily fixed.

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10689
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Preprocessor to check function parameters
« Reply #2 on: 2009-May-29 »
Yikes!! It should. Please post an example where it doesn't.

Offline FutureCow

  • HelpEditor
  • Prof. Inline
  • ******
  • Posts: 680
    • View Profile
Re: Preprocessor to check function parameters
« Reply #3 on: 2009-May-29 »
I tried pasting the example code from the help page in to see if I could get that to fail - and the test code compiles with a syntax error on the line
FUNCTION MAX: a, b

I'm buggered if I can see anything wrong with it!

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1772
    • View Profile
    • Homepage
Re: Preprocessor to check function parameters
« Reply #4 on: 2009-May-30 »
MAX is a command already?

Offline FutureCow

  • HelpEditor
  • Prof. Inline
  • ******
  • Posts: 680
    • View Profile
Re: Preprocessor to check function parameters
« Reply #5 on: 2009-May-30 »
I haven't been able to recreate the error yet, I will keep trying.

Please correct the example code for the Function command though.

* Function MAX needs to be renamed and the c=MAX(a,b) line changed accordingly (why doesn't the compiler give an error like "error : "MAX" already defined"?)
* In the "Title" function, the comments need "//" instead of "/"
* In the same function, the command "EXIT" needs to be replaced with the command "RETURN"
* If you don't comment out the first line "LOCAL a" you get the error
C:\glbasic\gpc_temp0.cpp: In function `int __GLBASIC__::__MainGameSub_()':
C:\glbasic\gpc_temp0.cpp:36: error: `a' is not a member of `__GLBASIC__'
« Last Edit: 2009-May-30 by FutureCow »