Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Line of sight
#21
I meant that floats are casted to doubles, in your example you are using ints and floats. That's not what I said:

Quote:all operands are automaticly type-casted to the width of the "int" type for integer values, or to the "double" type for floating point values

That's called type promotion. Of course, int is not automaticly casted to float 'cause you could lose precision in some cases (as in some integers can't be represented "exactly" in floating point). You have to explicitly cast int to float and float to int. The only automatic "expansion" is between numbers of the same "kind" (integers with integers, reals with reals). This done 'cause it's the best case scenario for calculations. If overflow happens, it should happen at the end of the evaluation, and not in between, when possible.

And yes, z88dk does this, just check the examples I posted. If the result is to be stored on an integer variable, or is to be passed to a function with an integer parameter, byte values are automaticly type-casted to int. And it isn't such a big deal, taking in account that the 30+ games we have released run quite nicely Wink

Anyhow, I just thought that this was somehow "natural" (for example, that you could shift left an unsigned byte not having to cast it to int yourself), at least it's what I'm used to (and I mean, I've been coding for 25 years now), and I thought that a compiler for a language like BASIC (which is considered to be a high level language) should implement. After all, it automaticly handles Strings already. Following the same logic, you could let us have to deal with strings ourselves, saving time and space in many cases Wink

I've been using the compiler since it's out so it's not a big deal for me. I just thought that it may be confusing to newcomers who are used to code in other languages. Specially in the case of calling a reserved word such as Draw or Print. I bet that anybody doing a Print a-b with a = 5 and b = 7 would expect a -2 to appear on screen, regardless of the type of a and b, and not a 254. A 254 is what I would expect to appear in an unsigned 8 bits "c" variable if a did a c=a-b, not as a result of printing a simple expression. It's what I find "natural".
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)