Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Compiler Returncode
#9
britlion Wrote:I can't see what's wrong with the compiler throwing up an error there? What's the problem?


poke uinteger @PropPrintTxtadr,txtadr

Has an issue - what is txtadr? Quite reasonably, the compiler doesn't know. So it assumes it's a float, and probably calls it zero. And warns you:

02:23:11 -> temp.bor:1: warning: Variable 'txtadr' declared as 'float'. Compilation failed

If you go with:

poke uinteger PropPrintTxtadr,txtadr

Well, now the compiler has two pieces of text that aren't numbers or defined variables. So it throws a fit about that too. It doesn't know what PropPrintTxtadr should be, so it defines a float, and tries to carry on. But it does warn you. (@text must refer to a label. Just text means it's a variable).

The problem is then, that if it's defined as a variable by the compiler, since it didn't know what to do with it, when it hits the label it REALLY throws a fit, because it's already defined PropPrintTxtadr...
The compiler is *not* failing at all. It's just a merely warning. That was what I was telling LCD previously. According to my tests it is returning a 0 return code (success). I will try on Windows, as the .exe version might be returning something different...

britlion Wrote:I'm a little confused - Am I missing something here? It seems pretty clear cut to me.
(Though, Boriel, if you are listening, I actually strongly DISLIKE this behavior - where something unknown is made into a variable automatically. I'd MUCH prefer the compiler to stop with an error, there. One mistyped variable name and the code still compiles; but obviously doesn't work... I'd rather know about it in no uncertain terms! Can we at least have a compiler option that makes it stop instead of warn if something isn't defined with a DIM or a LET already?)
This is what most compilers do. The warning is a warning because undeclared vars are Float by default with 0 value. So POKE Addr1, aValue (which is the same as Poke Byte Addr1, aValue), translates to POKE 0, 0. Addr1 is converted to Uinterger since a ZX Spectrum Memory address is always a 16 bit integer. Then aValue is converted to the given type to POKE (by default, a byte). If you do POKE @unknown, aValue, then the @unknown type is ok: it's always a memory address (the @operator returns that), but aValue is a float and must be rounded to a byte. That's the warning.

What you should do:
  • Warnings mean "Warning!", "Achtung!". If a program causes warnings, they must be examined one by one to see if they are potential bugs or not.
  • Avoid lower/uppercase mistyping by adding #pragma case_insensitive = TRUE at the beginning of your program (--case-insensitive still not exported to the command line)
  • There will be a flag --Werror (used in GNU gcc among others) that will turn warnings into errors.
  • There will be a flag to enforce variable declarations with --explicit or #pragma explicit (FreeBasic uses #pragma equivalent Option Explicit).
So just wait for the last 2 points, or examine them closely. I'm working slower now in the compiler (writing the Wiki), but all of this will be done.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)