View unanswered posts | View active topics It is currently Thu Jul 31, 2014 7:43 pm






Reply to topic  [ 23 posts ]  Go to page Previous  1, 2
1.38 BUG: errors at string and char[] operations 
Author Message
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 
hi,
@tyro: what will us tell your codes?
Is RobotC working faulty or is there just no ANSI-compatibility?

@developers: PLEASE make RobotC work like REAL C !!
This is actually what you have been advertising!!

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Tue Jul 01, 2008 11:03 am
Profile
Rookie

Joined: Wed Jun 25, 2008 9:38 pm
Posts: 6
Post 
Wonderful. Has anyone tried out StringDelete()? As far as I can see that procedure does nothing!!
(Which is incredibly annoying, since the documentation tells me something else.)
I also wonder why these things are procedures at all. They don't implement pointers: Fine. But then they should do some magic and make them functions, otherwise they don't simplify anything.

Anyway, please developers, implement StringDelete(), as well as some procedure to get a string out of chars!


Tue Jul 01, 2008 2:38 pm
Profile
Rookie

Joined: Wed Jun 25, 2008 9:38 pm
Posts: 6
Post 
Finally, I found at least a small part of the problem....

if you tell your program you would like to have to arrays of strings,

Code:
string a[16], b[16];

and then initialize the secound array before the first one,

Code:
b[0] = "Good stuff breaks"
a[0] = "Something else"

you will break your program.
I'm completely fed up with this stuff.


Wed Jul 02, 2008 7:33 am
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 
tyro wrote:
Wonderful. Has anyone tried out StringDelete()? As far as I can see that procedure does nothing!


what is this function or proc supposed to do anyway?
in what case is a string deletion needed for?
in C or C++ I don't know such a function name.
if you want a string to be "deleted" it will be the easiest way to assign it to a NullString :
string s;
char cstr[20];
s="";
cstr="";

ceterum censeo: RobotC has to become REAL C !

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Last edited by Ford Prefect on Tue Jul 08, 2008 5:09 am, edited 4 times in total.



Thu Jul 03, 2008 9:46 am
Profile
Rookie

Joined: Wed Jun 25, 2008 9:38 pm
Posts: 6
Post 
Very good question. I wanted to use this function as a replacement for the missing "substring" functionality (I still haven't found any stable way of working with substrings, and the missing pointers prevent me from finding an acceptable workaraound :cry:).

But now that I think about it: such a "delete" procedure is either predestined to mess up the memory, or to be slow and useless.


Sat Jul 05, 2008 6:12 am
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 
aaah - now that I read your post again, I guess I know what it's supposed to do:
stringdelete(mystring,2,5)
may delete in mystring 5 characters starting with position 2 (=3rd char) - or other way around... :roll:

but what should mystring be ? char array or C++ string ?

and in ANSI C
Code:
char chrstr[20]="abcdefg"

is a valid assignment! why not in RobotC?? :evil:

@dick swan, @tfriez,
could you plz give a statement to all of these string processing problems?
thx in advance!

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Tue Jul 08, 2008 2:41 am
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 
I tried the code again with the 1.38:
this original C code from a textbook does not work correctly (actually it doesn't work at all):

Code:
#define printf nxtDisplayTextLine
char name1[8], name2[8], temp[20];

task main(){
// here the original C code starts

strcpy(name1,"Athene");
strcpy(name2,"Zeus");
if (strcmp(name1,name2)>0)
{ strcpy(temp,name1);}
else
strcpy(temp, name2);
printf(1, "%s","bigger: ");
printf(2, "%s", temp);
strcpy(temp,"");
strcat(temp, name1);
strcat(temp, " & ");
strcat(temp, name2);
printf(3, "%s", "both: ");
printf(4, "%s", temp);

// here the original C code ends
while(true){};
}

the display shows just:

Quote:
bigger:
0
both:



instead of

Quote:
bigger:
Zeus
both:
Athene & Zeus

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Fri Jul 25, 2008 4:22 pm
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: 1.38 BUG: errors at string and char[] operations
Here's a post from Dick Swan (out of Bug Tracker);
My idea: maybe you can exchange
Code:
DisplayTextLine // RobotC dialect

by
Code:
printf // ANSI C syntax


in the following definition and add it to the file RobotCIntrinsics.c

Then you will have both, the RobotC/C++ string print command, and the ANSI C printf command for charstr.


Dick Swan wrote:
I've tested the code. The string functions -- strcpy, strcmp, strcat -- behave as exepected. The anomoly is in the print to LCD functions which does not behave as you expected.

The difficulty is that ROBOTC does not support VA_ARG style variable lists of procedure parameters. And C is a little inconsistent on how these are supported.
1. For short, int, long and float parameter types, C stores the value of the parameter on the parameter "stack".
2. For char parameter types, C stores a pointer to the parameter on the stack.

Most programmers will not use arrays of chars and instead will use ROBOTC's built-in (and memory leak, and bad pointer safe) "string" variable.

If you want to exact C-style formating, then change the definition of the "NxtDisplayTextLine" built-in function in the file RobotCIntrinsics.c. Change the existing definition to the attached.

One side effect of this change is that "%d" formating will not work with "byte" or "char" variables -- just like ANSI C. You have to cast to a short or int first. This is one of the reasons that this will not be a universal change in ROBOTC.

Here's the revised definitions.



#define DisplayTextLine(fmtType, type1, ref1, type2, ref2, default2)\
intrinsic void nxtDisplayTextLine(const int nLineNumber, const string &sFormatString, const type1 &parm1, const type2 &parm2 default2)\
asm(opcdNxtLCDDisplay, byte(nxtDsplyDrawTextLineVarVarFmtSpec), variable(nLineNumber),\
ref1(parm1), ref2(parm2),\
byte(fmtType), variableRefString(sFormatString))

DisplayTextLine(StringString,byte, variableRefByte, byte, variableRefByte, );
DisplayTextLine(StringShort, byte, variableRefByte, short, variableRefWord, );
DisplayTextLine(StringLong, byte, variableRefByte, long, variableRefLong, );
DisplayTextLine(StringFloat, byte, variableRefByte, float, variableRefFloat, );
DisplayTextLine(StringString,byte, variableRefByte, string, variableRefString, ="");

DisplayTextLine(ShortString, short, variableRefWord, byte, variableRefByte, );
DisplayTextLine(ShortShort, short, variableRefWord, short, variableRefWord, );
DisplayTextLine(ShortLong, short, variableRefWord, long, variableRefLong, );
DisplayTextLine(ShortFloat, short, variableRefWord, float, variableRefFloat, );
DisplayTextLine(ShortString, short, variableRefWord, string, variableRefString, ="");

DisplayTextLine(LongString, long, variableRefLong, byte, variableRefByte, );
DisplayTextLine(LongShort, long, variableRefLong, short, variableRefWord, );
DisplayTextLine(LongLong, long, variableRefLong, long, variableRefLong, );
DisplayTextLine(LongFloat, long, variableRefLong, float, variableRefFloat, );
DisplayTextLine(LongString, long, variableRefLong, string, variableRefString, ="");

DisplayTextLine(FloatString, float, variableRefFloat, byte, variableRefByte, );
DisplayTextLine(FloatShort, float, variableRefFloat, short, variableRefWord, );
DisplayTextLine(FloatLong, float, variableRefFloat, long, variableRefLong, );
DisplayTextLine(FloatFloat, float, variableRefFloat, float, variableRefFloat, );
DisplayTextLine(FloatString, float, variableRefFloat, string, variableRefString, ="");

DisplayTextLine(StringString,string, variableRefString, byte, variableRefByte, );
DisplayTextLine(StringShort, string, variableRefString, short, variableRefWord, );
DisplayTextLine(StringLong, string, variableRefString, long, variableRefLong, );
DisplayTextLine(StringFloat, string, variableRefString, float, variableRefFloat, );
DisplayTextLine(StringString,string, variableRefString, string, variableRefString, ="");

#undef DisplayTextLine
If you want to obtain C-style form

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Wed Aug 20, 2008 12:32 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 23 posts ]  Go to page Previous  1, 2

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.