Text variable passed in a function

More
2 weeks 4 days ago - 2 weeks 4 days ago #147 by ludojoey
Hello!

I'm not sure whether this is actually a bug, but perhaps it should be clarified in the manual (unless I simply missed it).

Here is the following code:

text t="ABCDEF";

byte x=5;

void func(text tt,byte y) {
   print(&tt," ",peek(&tt)," ");
   print(&y," ",peek(&y)," ");
   tt="GHIJK";
}

print(&t," ",peek(&t)," ");
print(&x," ",peek(&x)," ");

func(t,x);

print(&t," ",t," ");

The first two print statements produce the expected results.

However, the next two print statements (those inside the function "func") show a different address from the original variables, and while the numeric variable behaves as expected (its value is still 5), this is not the case for the variable of type "text".

Furthermore, modifying the variable "tt" inside the function does not modify the contents of the original variable "t".

This behavior does not seem to match the description given on page 96 of the Rev. E manual : 
"The text type is passed to functions as a reference using the regular text
identifier parameter syntax. When modifying the text inside the function, the
originally referenced text gets modified."


  
Last edit: 2 weeks 4 days ago by ludojoey.

Please Log in or Create an account to join the conversation.

More
2 weeks 4 days ago #150 by Franck
Yep something is clearly wrong, I'll have a look at it asap.
The following user(s) said Thank You: ludojoey

Please Log in or Create an account to join the conversation.

More
2 weeks 3 days ago #151 by Franck
Fixed in upcoming version 0.7.8

A new example has been added in examples/coding/ to further explain the concepts.
The following user(s) said Thank You: ludojoey

Please Log in or Create an account to join the conversation.

Time to create page: 0.164 seconds
Powered by Kunena Forum