NXC: strlen vs. StrLen
NXC: strlen vs. StrLen
hello,
for NXC: what are the differences between strlen vs. StrLen ?
for NXC: what are the differences between strlen vs. StrLen ?
-
- Posts: 358
- Joined: 01 Oct 2010, 06:37
- Location: Denmark
- Contact:
Re: NXC: strlen vs. StrLen
AFAIK, StrLen was renamed into strlen so that it correspond to the C function. StrLen still exists for backwards-compatibility. There is a couple of functions that are like that, however some might be macro versions, while others aren't iirc.
Anyway, both functions both uses ArrLen and then subtract one, no matter where NULL actually is...
Anyway, both functions both uses ArrLen and then subtract one, no matter where NULL actually is...
My blog: http://spillerrec.dk/category/lego/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
-
- Posts: 224
- Joined: 30 Oct 2010, 04:10
- Location: 127.0.0.1
- Contact:
Re: NXC: strlen vs. StrLen
2/07 test release, level 2 optimization.
StrLen():
strlen():
StrLen():
Commit to Lego Mindstorms StackExchange Q&A http://area51.stackexchange.com/proposals/4105
Minboards IRC Channel #mindboards on Freenode
My blog: http://timpattinson.wordpress.com/
Minboards IRC Channel #mindboards on Freenode
My blog: http://timpattinson.wordpress.com/
Re: NXC: strlen vs. StrLen
I would not prejudge your evaluation now - but at first glance, it looks as if strlen code is shorter...
any other significant differences?
any other significant differences?
-
- Posts: 224
- Joined: 30 Oct 2010, 04:10
- Location: 127.0.0.1
- Contact:
Re: NXC: strlen vs. StrLen
I don't know, it appears smaller and faster, but i'm a n00b at reading asm
It also appears the call has been omitted from the version using
It also appears the call has been omitted from the version using
strlen()
Commit to Lego Mindstorms StackExchange Q&A http://area51.stackexchange.com/proposals/4105
Minboards IRC Channel #mindboards on Freenode
My blog: http://timpattinson.wordpress.com/
Minboards IRC Channel #mindboards on Freenode
My blog: http://timpattinson.wordpress.com/
-
- Posts: 358
- Joined: 01 Oct 2010, 06:37
- Location: Denmark
- Contact:
Re: NXC: strlen vs. StrLen
Please be aware that the optimizer might remove unneeded code and this is why the second program is smaller, it is simply empty...
Remember to use TextOut/NumOut or at least something to make sure the calculated values are actually used. (It is interesting that only one of the functions disappear though.)
Remember to use TextOut/NumOut or at least something to make sure the calculated values are actually used. (It is interesting that only one of the functions disappear though.)
My blog: http://spillerrec.dk/category/lego/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
Re: NXC: strlen vs. StrLen
Here's the code without it being removed by the optimizer:
John Hansen
Code: Select all
task main()
{
NumOut(0, LCD_LINE1, strlen("Hello, world"));
/*
strcat __strbufmain, __constStr0009
mov __strlen_7qG2_str_7qG2_000_inline_main, __strbufmain
arrsize __D0strlen_inline_main, __strlen_7qG2_str_7qG2_000_inline_main
sub __D0main, __D0strlen_inline_main, __constVal1
*/
NumOut(0, LCD_LINE2, StrLen("Hello, world"));
/*
strcat __strbufmain, __constStr0009
arrsize __D0main, __strbufmain
sub __D0main, __D0main, __constVal1
*/
}
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
http://bricxcc.sourceforge.net/
Who is online
Users browsing this forum: No registered users and 0 guests