Hopefully a simple question.
BlitzMax Forums/BlitzMax Module Tweaks/Hopefully a simple question.
| ||
Well, I am trying to modify the String type and add a function that returns a pointer to it's data and I've run into a problem First things first - all of the files I reference are in this subdirectory: mod\brl.mod\blitz.mod Here is the function I added to blitz_string.c BBChar *bbStringReference( BBString *str ){ return str->buf; } Buf is an array of type BBChar. Looking in blitz_types.h I found BBChar to be an unsigned short. Well, for my current purposes I don't need unicode support and want standard 1 byte characters, so I changed the typedef for BBChar to an unsigned char. I initially just added the function without changing BBChar, and made a test program using a short pointer. The following code worked Extern Function StringReference:Short Ptr( str$ ) = "bbStringReference" EndExtern global test$ = "This is a test string" global shptr:short ptr shptr = StringReference( test ) for local iter = 0 until test.length print chr(shptr[iter]) 'printed the string one character per line next for local iter2 = 0 until test.length shptr[iter2] = Asc("B") next print test 'printed BBBBBBBBB etc Now after I changed BBChar to an unsigned char,and changing the short ptr to a byte ptr, things got screwy. Doing a print loop like above only printed the first character and then stopped. Lo and behold, turning the return type from byte ptr back to short ptr and turning my pointer itself back to a short pointer made everything work again. Why is the string's buf field still an array of shorts?? I should mention that I got the following error when trying to rebuild all modules after changing BBChar to an unsigned char. C:/Program Files/BlitzMax/mod/brl.mod/blitz.mod/blitz_string.c: In function `bbStringFromWString': C:/Program Files/BlitzMax/mod/brl.mod/blitz.mod/blitz_string.c:184: warning: passing arg 1 of `bbStringFromShorts' from incompatible pointer type C:/Program Files/BlitzMax/mod/brl.mod/blitz.mod/blitz_string.c: In function `bbStringTrim': C:/Program Files/BlitzMax/mod/brl.mod/blitz.mod/blitz_string.c:266: warning: passing arg 1 of `bbStringFromShorts' from incompatible pointer type C:/Program Files/BlitzMax/mod/brl.mod/blitz.mod/blitz_string.c: In function `bbStringFind': C:/Program Files/BlitzMax/mod/brl.mod/blitz.mod/blitz_string.c:296: warning: passing arg 1 of `charsEqual' from incompatible pointer type C:/Program Files/BlitzMax/mod/brl.mod/blitz.mod/blitz_string.c:296: warning: passing arg 2 of `charsEqual' from incompatible pointer type C:/Program Files/BlitzMax/mod/brl.mod/blitz.mod/blitz_string.c: In function `bbStringFindLast': C:/Program Files/BlitzMax/mod/brl.mod/blitz.mod/blitz_string.c:308: warning: passing arg 1 of `charsEqual' from incompatible pointer type C:/Program Files/BlitzMax/mod/brl.mod/blitz.mod/blitz_string.c:308: warning: passing arg 2 of `charsEqual' from incompatible pointer type Looking at the chode is leaving me stumped. I don't get how it's an 'incompatible pointer type'? Also, did these errors prevent string.c from being rebuilt and is this perhaps why the buf field is still an array of shorts instead of unsigned chars? Please help a newbie! :) |
| ||
Those are just warnings- they won't stop the code from being generated but they are there for a reason. Those functions are declared with short pointers, so at some point you would have to modify them to use char pointers. However, that's not the problem. When Max generates static strings, it does so at the compiler level - and generates unicode strings. Modify your code again and rebuild your program using byte ptrs, then look at the output .s (assembler source) file - in there you'll see the static string - notice it will have been generated as unicode. Here's an example so you know what to look for :- _19: dd _bbStringClass dd 2147483647 dd 11 dw 104,101,108,108,111,32,119,111,114,108,100 That is the static string object (created when you do something like test$ = "hello world" that dw means 'word size' data and is the unicode values of the characters "hello world". |