| Imadatobanisa (647) | |||||
|
Oh, the hell? STRCPY :
STRCAT :
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
|
|||||
| L B (3816) | |
|
Have you checked their requirements about source and target overlaps? Also, don't use char arrays. | |
|
|
|
| Imadatobanisa (647) | |||||
|
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
At least in my opinion it's better than :
I have no idea should I remove the ugly bracket [] form? Any idea or suggestion? | |||||
|
Last edited on
|
|||||
| EssGeEich (1009) | |||
Oh, god, please ban. Let me, oh, let me call EssGeEich::~EssGeEich();
| |||
|
Last edited on
|
|||
| Imadatobanisa (647) | |
|
...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. | |
|
|
|
| EssGeEich (1009) | |||||||
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:
I hope it was clear enough~ This is becoming kinda stressing - And -
| |||||||
|
|
|||||||
| Imadatobanisa (647) | |
|
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
|
|
| L B (3816) | |||
http://www.cplusplus.com/reference/cstring/strcat/
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. | |||
|
|
|||
| Imadatobanisa (647) | |
|
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
|
|
| EssGeEich (1009) | |
Yeah, that's the reason. About the question above, you mean dereferencing it? you use *pointer for that.
| |
|
|
|
| chrisname (6191) | |
| Don't do it EssGeEich, you have so much to stay in scope for! | |
|
|
|
| EssGeEich (1009) | |||
Someone deleted my pointer, but I was on the stack! What's gonna happen to me now? D: | |||
|
|
|||
| Script Coder (456) | |||
hope that some idiot noob makes some horribly incorrect code and saves you | |||
|
|
|||
| Imadatobanisa (647) | |||
|
Pointless, My question is : How to convert a pointer value itself to a r-value (not about dereferencing a pointer) And, which is better?
| |||
|
Last edited on
|
|||
| EssGeEich (1009) | |
| Isn't it a rvalue already? Show some code and what you mean. | |
|
|
|
| Imadatobanisa (647) | |||
| |||
|
Last edited on
|
|||
| EssGeEich (1009) | |
| And what's wrong? | |
|
|
|
| Imadatobanisa (647) | |||
The compiler generated a compling error. It says : "cannot convert double* to int" :( | |||
|
|
|||
| Coder7777 (4) | ||
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
|
||
| EssGeEich (1009) | |
| 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. | |
|
|
|