Inner wrote:matthew180 : I didn't know this was such a saw point .. maybe I should be making a bigger thing over it!.. I shall write more after tea I think.
Well, I don't like to suggest something without a solution, and I like to make sure everyone understands exactally what I'm trying to point out.
Fred wrote:I was talking about MIXING unsigned and signed numbers in expressions, comparisons and more. Doing all in unsigned is of course very easy. Think than even VC++ warns you when you do a such comparison between signed and unsigned because performances and unexpected result and ask for cast. Do you want casts be introduced in a basic langage ? Anyway, if you can give the solution, I'm will be of course very glad.
I still don't understand what you mean by "performance" problems? No matter what compiler or language you use, variables of different types will be converted to the same type before being compared. And this conversion can be done at compile time (usually with the selection of JLE or JBE, etc.), so I don't see where that slows things down.
As for casting, yes, I think you need to introduce it. You ask "Do you want casts be introduced in a basic langage ?" as if casting is something that should not be in a BASIC language, but pointers, structures, and linked lists should be... I've already argued that PB is way beyond BASIC already and adding these additional features makes it more usable.
http://www.wikipedia.org/wiki/BASIC
The eight design principles of BASIC were:
1. Be easy for beginners to use
2. Be a general-purpose language
3. Allow advanced features to be added for experts (while keeping the language simple for beginners)
4. Be interactive
5. Provide clear and friendly error messages
6. Respond fast for small programs
7. Not require an understanding of computer hardware
8. Shield the user from the operating system
Well, PB already blows this list... Look at number 7 for example and try to do games without knowing anything about your hardware... And number 8, well, that's a utopia of computer languages. To sheild someone from the OS you can't add things like graphic or sound. However, number 3 allows you to add anything to PB that you want! The only thing BASIC about PB anymore is the name...
So, again, yes, I want casting. You can't have more types without it. You have already crossed the line with sizes anyway, allowing the user to worry about .b or .w or .l size types. I would also like to see quads (64-bit) integers and floats added to PB. Since the IA32 processors have commands to directly supporting such types, this would again be choices the PB compiler makes at compile time.
For people who don't give a crap about types and casting, they can just use the default .l type, and they will never have any problems. For those who *need* bigger types, or unsigned types, etc., it should be there, otherwise we have to go use other languages...
As for implementation, I can't do it for you unless you give me read access to the PB compiler source... But, I can give you the rules for casting, which should make initial implementation easy since PB only has a small subset of types compared to C.
---
Any expression to be calculated breaks down into a series of operations between two operands. For example, the expression 2*3-4+5 amounts to the series 2*3 resulting in 6, 6-4 resulting in 2, and finally 2+5 resulting in 7. Thus, the rules for casting operands where necessary only need to be defined in terms of decisions about pairs of operands. So, for any pair of operands of different types, the following rules are checked in the order shown, and when one rules applies, that rule is used.
Rules for Casting Operands
1. If either operand is of type "long double", the other is converted to "long double".
2. If either operand is of type "double", the other is converted to "double".
3. If either operand is of type "float", the other is converted to "float".
4. Any operand of type "char", "signed char", "unsigned char", "short", or "unsigned short" is converted to type "int".
5. An enumeration type is converted to the first of "int", "unsigned int", "long", or "unsigned long" that accommodates the range of the enumerators.
6. If either operand is of type "unsigned long", the other is converted to "unsigned long".
7. If one operand is of type "long" and the other is of type "unsigned int", then both operands are converted to type "unsigned long".
8. If either operand is of type "long", the other is converted to type "long".
This is not as complex as it looks. The basic principle is to always convert the value that has the type that is of a more limited range, to the type of the other value. This maximizes the likelihood of being able to accommodate the result.
Matthew