strings and 1.0.0.2F

Discuss the Firewing language

strings and 1.0.0.2F

Postby Jerry Messina » Tue Aug 27, 2013 10:45 pm

Could you elaborate a bit on the new string functionality in 1.0.0.2 (F) BETA?
Jerry Messina
 
Posts: 280
Joined: Thu Feb 14, 2013 10:16 am

Re: strings and 1.0.0.2F

Postby David John Barker » Wed Aug 28, 2013 12:48 pm

There was a problem with the "F" revision, make sure you have downloaded "G". Anyway...

> Could you elaborate a bit on the new string functionality in 1.0.0.2

By default, if you declare a string it is 32 characters long plus null terminator. In the past this was fixed, so if your string went over this number you needed to dimension it explicitly. This can be problematic as sometimes it's not always obvious that a string will go over the character limit. It can also be very problematic for strings passed by value. Parameter variables are adjusted to accommodate the largest string passed to it, but don't get re-dimensioned in the sub or function itself. For example,
Code: Select all
sub mySub(str as string)
   str = "string is : " + str
   console.write(str,13,10)
end sub

sub main()
   mySub("hello world")
end sub

here the parameter "str" is dimensioned to the length of "hello world". However, it can be seen that "str" needs to grow inside the function to accommodate the concatenation (remember that Firewing uses a compile time stack, not runtime, so it must calculate the max size of string at compile time). In previous versions of the compiler, this would almost certainly cause serious problems at runtime. The above is a fairly obvious example, but in some cases it's not always obvious that a string will extend beyond its dimensioned bounds.

The latest version of the compiler gets around this problem by "extending" the size of the string, if an expression assigned to it is likely to go beyond its original size. It also makes it easier to write code such as
Code: Select all
dim str as string = "this is my very long sentence which will automatically increase the size of the declared string"

This addition should make for much more robust code. Note that extreme use of string concatenation will increase the size of the stack used over previous compiler versions (i.e. more RAM used) but because the stack is recycled, this should not cause any difficulties. Also note that you still need to take care when passing string "byref" - that is, make sure that they are dimensioned correctly before you pass them by reference.
User avatar
David John Barker
 
Posts: 491
Joined: Thu Nov 08, 2012 12:21 pm


Return to Language

Who is online

Users browsing this forum: No registered users and 6 guests

x