New child language - (Function member address (structure))

Pages: 1... 1314151617... 20
Jan 14, 2013 at 10:51am
Oh, the hell?

STRCPY :
1
2
3
4
char string[100];
strcpy(string, "sdklfklsdfsd");

strcpy(string,string); //works OK 


STRCAT :
1
2
3
4
char string[100];
strcpy(string, "sdklfklsdfsd");

strcat(string,string); //Crash!!!! 


I see both two functions have the same syntax : (char*, const char*), but why does it crash? I completely have no idea.... :(
Last edited on Jan 14, 2013 at 10:51am
Jan 14, 2013 at 12:32pm
Have you checked their requirements about source and target overlaps?

Also, don't use char arrays.
Jan 14, 2013 at 1:25pm
Thanks L B! These must be a hidden error at somewhere in the function STRCAT.
Because also the default C++ code cannot solve this, and the returning value most likely is undefined. Just call it "UNDEFINED BEHAVIOR"


NEW TYPE-CAST!!!! Users now can use and apply type-cast directly for a value by using the form looks like : int(...); char(...); unsigned int(...);. As you can see this looks like a function, and I used this tweak to make this.
NOTE : Still useless if you write (int)(10 * 22.2) //It should be a function

1
2
double d = 100;
int m = int(d = modf(87.55, &d));


At least in my opinion it's better than :

 
int m = [int](d = modf(87.55, &d));


I have no idea should I remove the ugly bracket [] form? Any idea or suggestion?
Last edited on Jan 14, 2013 at 1:56pm
Jan 14, 2013 at 1:55pm
Jackson Marie wrote:
These must be a hidden error at somewhere in the function STRCAT.
Because also the default C++ code cannot solve this, and the returning value most likely is undefined. Just call it "UNDEFINED BEHAVIOR"


Oh, god, please ban.

Let me, oh, let me call EssGeEich::~EssGeEich();
Last edited on Jan 14, 2013 at 1:57pm
Jan 14, 2013 at 2:03pm
...The next step is POINTER. It's also the most difficult challenge. Any idea if I'm going to make a new pointer structure?

EssGeEich - What? My interpreter currently doesn't support this.
Jan 14, 2013 at 2:12pm
Jackson Marie wrote:
EssGeEich - What? My interpreter currently doesn't support this.

You don't understand things on the fly, do you?

The strcat crash is NOT undefined behaviour, WHAT does make you think it is Undefined Behaviour?

If you care to read L B's post:
L B wrote:
Have you checked their requirements about SOURCE AND TARGET OVERLAPS?


I hope it was clear enough~ This is becoming kinda stressing - And -
Jackson Marie wrote:
Any idea if I'm going to make a new pointer structure?
Huh?
Jan 14, 2013 at 2:30pm
Oh I'm sorry, there was a lot of things and actually I was very confused because I only tried to call strcat. More crazily, I tried to figure out every assembly code and made a similar function strcat. The function works fine, then why does the standard function crashs? So just a few doubt questions. :)

And about pointer, probably I'm not going to make a whole structure for pointers, but I have an idea...

How to convert a pointer to a r-value?
Last edited on Jan 14, 2013 at 10:48pm
Jan 14, 2013 at 2:38pm
http://www.cplusplus.com/reference/cstring/strcat/
strcat wrote:
destination and source shall not overlap.

This means that the first parameter cannot be in any way similar to the second, or it will crash. The fact that it doesn't work is defined right there in black and white.

You can't expect someone without legs to be able to run and jump just because their twin brother can.
Jan 14, 2013 at 2:59pm
Wow, I figured out why the function crashs. :)

If you call the function strcat like this, the possible cause : At beggining, the function replaces the terminator null character with the first character of the character array. Then most likely the program will enter an infinite loop - only trying to search the null character (actually the null character has been replaced before). The null character (or the end of string) is never met or reached because both the length of the destination and source string are continuously growing up and up. Finally it causes "overflow". And a crash error begins!!!

Thank you L B, at least you are very smart!
Last edited on Jan 14, 2013 at 3:11pm
Jan 14, 2013 at 3:42pm
Yeah, that's the reason. About the question above, you mean dereferencing it? you use *pointer for that.
Jan 14, 2013 at 6:18pm
Don't do it EssGeEich, you have so much to stay in scope for!
Jan 14, 2013 at 6:27pm
chrisname wrote:
Don't do it EssGeEich, you have so much to stay in scope for!

Someone deleted my pointer, but I was on the stack! What's gonna happen to me now? D:
Jan 14, 2013 at 7:35pm
EssGeEich wrote:
Someone deleted my pointer, but I was on the stack! What's gonna happen to me now?


hope that some idiot noob makes some horribly incorrect code and saves you
Jan 14, 2013 at 8:35pm
Pointless, My question is : How to convert a pointer value itself to a r-value (not about dereferencing a pointer)

And, which is better?

1
2
3
4
double d1 = double(100);
double d2 = [double]100;
double d3 = double(int(sqrt(125.00)));
double d4 = [double]([int]sqrt(125.00));
Last edited on Jan 14, 2013 at 8:37pm
Jan 14, 2013 at 8:44pm
Isn't it a rvalue already? Show some code and what you mean.
Jan 14, 2013 at 8:53pm
1
2
3
4
double abc;
double *lpftemp = &abc;

int pointer_value = (int)lpftemp;
Last edited on Jan 14, 2013 at 8:55pm
Jan 14, 2013 at 11:06pm
And what's wrong?
Jan 14, 2013 at 11:12pm
 
int pointer_value = (int)lpftemp;


The compiler generated a compling error.
It says : "cannot convert double* to int" :(
Jan 14, 2013 at 11:18pm
It says : "cannot convert double* to int" :(
Sigh...

Keep working on it Jackson but really I do think you need a little bit more experience to do a interpreter I think that is what your doing atleast
Last edited on Jan 14, 2013 at 11:19pm
Jan 15, 2013 at 2:20am
This doesn't mean the pointer isn't a lvalue. Anyways are you sure your error shows up with the code you posted? Typecasting enum types always works - and a pointer is a number.
Pages: 1... 1314151617... 20