ReadLnString not working (SAMBA mode)
-
- Posts: 117
- Joined: 27 Dec 2010, 19:27
ReadLnString not working (SAMBA mode)
Hey all,
Can anyone confirm if ReadLnString() NXC function is working under my conditions: 1.031 firmware, brcxcc 3.3.8.10 and compiler 1.2.1.r4 ?
In my case, it enters in SAMBA mode (the clicking mode, right?)
Cheers,
Ricardo
Can anyone confirm if ReadLnString() NXC function is working under my conditions: 1.031 firmware, brcxcc 3.3.8.10 and compiler 1.2.1.r4 ?
In my case, it enters in SAMBA mode (the clicking mode, right?)
Cheers,
Ricardo
Re: ReadLnString not working (SAMBA mode)
If you don't have the enhanced 1.31 firmware, download it. It will make your life easier. That might be the reason why it's not working.
Thanks, and have a nice day,
nxtboy III
programnxt.com
nxtboy III
programnxt.com
-
- Posts: 117
- Joined: 27 Dec 2010, 19:27
Re: ReadLnString not working (SAMBA mode)
OK, I got the problem! It's nothing about ReadLnString(). Sorry...
I was using strcat() with a destination string with no content. I wonder if this shouldn't be possible. In C it works well, as far as the first char of a string is a '\0'. I know NXC works a bit differently, but I think this shouldn't crash:
Is this failing by purpose?
I was using strcat() with a destination string with no content. I wonder if this shouldn't be possible. In C it works well, as far as the first char of a string is a '\0'. I know NXC works a bit differently, but I think this shouldn't crash:
Code: Select all
string msg;
strcat(msg, "Hello"); //nothing in "msg" in the first use of strcat()
Re: ReadLnString not working (SAMBA mode)
You should initialize msg to "".ricardocrl wrote:Is this failing by purpose?Code: Select all
string msg; strcat(msg, "Hello"); //nothing in "msg" in the first use of strcat()
In C, if you do:
Code: Select all
typedef char *string;
string msg;
msg = "Hello";
How does this relate to NXC? Well, my guess is, it tries to access the memory that msg points to (within the VM), and then waits until the value of the string is returned. It isn't since it can't access itself, and I'm obviously not making any sense.
-----
Short answer:
Patient: "Doctor, it hurts when I whack myself on the head with a very large value of pie."
Doctor: "Don't do that. Unless it's a scientific experiment."
Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE
Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
-
- Posts: 117
- Joined: 27 Dec 2010, 19:27
Re: ReadLnString not working (SAMBA mode)
Well, maybe I don't make much sense either, but, once we don't specify the size of a string in NXC, every time we use strcat(), it will reallocate the space for a bigger string. If by default, a declared string is empty, I think it should reallocate space in the first use of the function.
Of course, when I mentioned the situation in C, I'm referring to an array of chars with the first char being null '\0', not just a pointer.
Of course, when I mentioned the situation in C, I'm referring to an array of chars with the first char being null '\0', not just a pointer.
Re: ReadLnString not working (SAMBA mode)
It is not in SAMBA mode, even though it is clicking. The firmware VM crashes and the brick clicks but all you need to do is pull a battery and put it back in and the brick reboots without requiring a firmware re-flash. If it was in SAMBA mode then the only way to recover would be to download a new firmware image to the brick.
It looks like a firmware bug since the code should not crash the VM. Can you try this with the standard firmware to check whether I broke something in the enhanced firmware?
I just tried the standard firmware myself and it also crashes when this code executes. With string msg = ""; rather than string msg; neither firmwares crash. The difference is that the initialized string actually contains one element (the null terminator) while the uninitialized string is completely empty. This appears to kill the strcat opcode. I will add some code to the compiler so that all string variables are actually initialized with a null even if no explicit initializer is provided.
John
It looks like a firmware bug since the code should not crash the VM. Can you try this with the standard firmware to check whether I broke something in the enhanced firmware?
I just tried the standard firmware myself and it also crashes when this code executes. With string msg = ""; rather than string msg; neither firmwares crash. The difference is that the initialized string actually contains one element (the null terminator) while the uninitialized string is completely empty. This appears to kill the strcat opcode. I will add some code to the compiler so that all string variables are actually initialized with a null even if no explicit initializer is provided.
John
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
http://bricxcc.sourceforge.net/
-
- Posts: 117
- Joined: 27 Dec 2010, 19:27
Re: ReadLnString not working (SAMBA mode)
Ah, thanks for the clarification. I had this doubt for a long time.afanofosc wrote:It is not in SAMBA mode, even though it is clicking. The firmware VM crashes and the brick clicks but all you need to do is pull a battery and put it back in and the brick reboots without requiring a firmware re-flash. If it was in SAMBA mode then the only way to recover would be to download a new firmware image to the brick.
John
I tried now with the standard firmware 1.29 and it crashes as well.
Code: Select all
task main(){
string msg;
strcat(msg, "Hello");
TextOut(0, LCD_LINE1, msg);
Wait(2000);
}
Code: Select all
msg = StrCat(msg, "Hello");
Who is online
Users browsing this forum: No registered users and 2 guests