On Tue, 14 Apr 2009, Pritpal Bedi wrote: Hi,
> NOTE: In xHarbour ONE character string is treated as a number > so you were able to compare as above. I know that in C it works like > it is implemented in xHarbour but we are accustomed to the language > CLIPPER. It's not like in C and never was. I do not understand why Ron is repeated that it tries to mimic C because it's not true. In C you cannot make: "A" == 65 You can only use special operator to extract character value as number be enclosing it in ''. But it's not a one byte string. It's numeric value written in special way. Just like any number starting with 0x is hexadecimal number or any number starting with 0 is octal number. So xHarbour is not even close to any C rules in the above. This extension is local to xHarbour and does not exists in other languages I know. If you want to make sth close to C then it should be bound with [] operator used for string, f.e. you can make in C: "ABC"[1] and it returns numeric value equal to "B" character representation. So in Harbour it should return number, f.e.: ? ABC[2] // 66 on ASCII based machines or: s := "ABC" s[2] := 42 ? s // "A*C" In the past Harbour had such extension added by Ryszard and it was working quite well without anomalies which have to appear in xHarbour like implementations which operates on one byte strings not numbers like C or the old Harbour code, f.e. this code: x:="ABC" ? x[1,1,1,1,1,1,1,1,1] will not generate any RT error because 1 is always valid string but also this code: porc main local x:="ABC" ? x[1,2,3,4,5,6,7,8,9,0,-1,2,3-0-4,5,-0x1234465abc] return will not generate any RT error because in xHarbour [] operator used for strings try to mimic substr() behavior. It means the if user have multi dimensional array or hash array and then by mistake will overwrite one of its items by string then xHarbour VM will accept any stupid indexes for this string without any RT error. In the past when I was working with xHarbour I made such mistake twice and it cost me a lot of time to locate the real reason of problem. > Now I know that in one of projects under my supervision blow up randomely > and error log always report that comparison operands are not of same > type. > Hope you may be clear now. > BTW there is some compiler switch in Harbour which mimmics this behaviour. > correct and complete me if right ... You can use -ks and then overload [] used for string. You can also overload all other operators using scalar classes. In XHB library we _Character and _Numeric classes which emulates xHarbour behavior but I added only arithmetic operators (+, -, *, ...) without any relational ones (==, =, <, ...). I'll add them in some spare time or user can easy make it yourself. But I suggest to rather clean the code then use such things. best regards, Przemek _______________________________________________ Harbour mailing list Harbour@harbour-project.org http://lists.harbour-project.org/mailman/listinfo/harbour