String concatenation rules seem to have changed in v4.5

Moderator: Benj

Post Reply
Brian Walsh
Posts: 29
Joined: Thu Jan 14, 2010 10:43 pm
Has thanked: 3 times
Contact:

String concatenation rules seem to have changed in v4.5

Post by Brian Walsh »

I revisited a program written in an earlier version today. Two things didn't work when I recompiled it into a PIC18F4620 using v4.5.

1. The software USART produced garbage. Originally, I had to specify a strange custom baud rate to get 9600 to work. It is obvious to me now that Matrix have fixed the timing therefore the bodge rate in my program no longer flies. That's a gotcha - c'est la vie.

2. The following string concatenation scheme failed also:

message = FloatToString$(raise_min_speed)
message = "raise initial min speed = " + message
message = message + crlf

This produces "raise initial speed = 20.000" say, in earlier versions, but produces a stammering repetition of the string constant with no occurrence of the string variable in the output string in v4.5.

I can see ways to fix this, but I would really like to know the official rules. I deduced, that in previous versions only one function is allowed on a single line. Also, if a single variable is to be used, the variable type conversion has to come first, followed by a reverse concatenation and then, finally, the attachment of crlf.

So why doesn't this work anymore and where can I find a complete definition of the syntax for string concatenation in flowcode?

Thanks.

Brian Walsh.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: String concatenation rules seem to have changed in v4.5

Post by Benj »

Hello Brian,

Sorry to hear about the problems you've been having.

The reason is the existing string concat functions cant do 'a = b + a' as 'b' overwrites 'a'. The solution is that if the second argument is also the destination, copy the strings backwards.

For example.

message = "raise initial min speed = "
message = message + FloatToString$(raise_min_speed)
message = message + crlf

User avatar
Steve
Matrix Staff
Posts: 3421
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Re: String concatenation rules seem to have changed in v4.5

Post by Steve »

And I believe in V5 we have fixed it so "a = a+b" and "a = b+a" both work, so this issue only affects V4 of Flowcode.

Brian Walsh
Posts: 29
Joined: Thu Jan 14, 2010 10:43 pm
Has thanked: 3 times
Contact:

Re: String concatenation rules seem to have changed in v4.5

Post by Brian Walsh »

Hi Ben,

Your reply shows the obvious and straightforward way of building the string and I would have done it that way but it doesn't work. Line two of your solution has two functions ( + & FloatToString$ )on one line which is not allowed. The editor highlights the line as being faulty and won't accept it.

As to the overwriting explanation - it worked in previous versions so why not in this one?

Is there a written statement of the definitive syntax available so I can strictly adhere to it and avoid writing piles of code that might stop working in future versions.

Regards,

Brian Walsh.

User avatar
Steve
Matrix Staff
Posts: 3421
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Re: String concatenation rules seem to have changed in v4.5

Post by Steve »

To get around your problem, you should do the following:

Code: Select all

message = "raise initial min speed = "
message2 = FloatToString$(raise_min_speed)
message = message + message2 
message = message + crlf
The overwriting issue been around for a while now (v4.3 also had this issue). This was due to a change in the code to reduce the RAM used by these functions. The original functions always used an intermediate variable to hold the result, which often doubled the RAM usage of the function and prevented string functions from being used on chips with smaller amounts of RAM.

Brian Walsh
Posts: 29
Joined: Thu Jan 14, 2010 10:43 pm
Has thanked: 3 times
Contact:

Re: String concatenation rules seem to have changed in v4.5

Post by Brian Walsh »

Hi Steve,

Thanks for the explanation. I was aware that the original message would have to be preserved somehow for the a = b + a syntax to work and when it did, magically, in the Flowcode version used for the original application, I thought no more about it. I now understand your RAM economy reasons for removing the magic and implementing the function in a way where only a = a + b will work in the expected fashion, although I don't understand why you keep taking it in and out. Your first reply said you had re-introduced it in v5.

The solution now offered uses two variables rather than one and avoids the two functions on a line problem. This way at least the programmer knows what's going on and you are free to do as you wish with your concatenation function in future versions.

The messages I am composing, as you will have guessed, are output via RS232 to a terminal program. My solution was to simply break the thing up sending the literal string first with no crlf and then, using the same string variable, do the float to string + crlf and then send that. No additional variable required but, of course, a little more code space is used. The terminal provides the essential additional RAM.

I suppose this all comes down to the fact that whereas general policy dictates that users should always update to the latest version of Flowcode, they should be aware that when they do so, applications written under previous versions may not compile to chip and run correctly without potentially extensive editing.

Simply reproducing a chip based on an older version or making a minor mod can turn into a major headache. Would you recommend keeping older versions of Flowcode for such purposes? Is this allowed or, indeed, possible? Are earlier versions available for download?

Despite this rant, I think your product is great! Why do I not know about v5? Has it been released and if so how do I upgrade?

Regards,

Brian Walsh.

User avatar
Steve
Matrix Staff
Posts: 3421
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Re: String concatenation rules seem to have changed in v4.5

Post by Steve »

Upgrading always has the potential to make a working program stop working, but we do try our best to avoid this situation. Where a problem like this occurs, we will work as a matter of urgency to solve it.

While it may be difficult to keep installs of "minor" upgrades (e.g. v4.3 to v4.5) on the same PC, the upgrade from V4 to V5 should allow for both to be on the same PC at the same time. This will hopefully minimise upgrade problems. But be aware that a V5 program that has been edited and resaved will no longer open in V4. So always make sure you keep your V4 program archived.

There are many changes and improvements to the generation of code in V5, so we will be monitoring the situation very closely once V5 has been released. It is due later this month.

User avatar
JonnyW
Posts: 1230
Joined: Fri Oct 29, 2010 9:13 am
Location: Matrix Multimedia Ltd
Has thanked: 63 times
Been thanked: 290 times
Contact:

Re: String concatenation rules seem to have changed in v4.5

Post by JonnyW »

Hi Brian.
I don't understand why you keep taking it in and out. Your first reply said you had re-introduced it in v5.
Just a note - in v5 the compilation and code generation works quite differently from v4, so we have the opportunity to add little things like this back in. The code for v5 may use a little more ROM but does not use an extra temporary string, so hopefully everyone will be happy.

Jonny

Post Reply