You know I appreciate your postings, I feel like a better programmer for reading them sometimes... I gotta start copying them out of this forum in case I wake up and it's gone one day. Thanks for the examples!
MarauderIIC wrote:You know those people that are like "CHECK IT OUT I just made Linux run on this piece of celery [or other random object]!!"? Yeah, that's Falco, but with ES.
Dear god, they actually ported ES to a piece of celery!
Martin Golding wrote:
"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live."
Trask wrote:You know I appreciate your postings, I feel like a better programmer for reading them sometimes... I gotta start copying them out of this forum in case I wake up and it's gone one day. Thanks for the examples!
np mate. just trying to spread the knowledge.
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
avansc wrote:
there are many str functions in C, strcmp() strcat() and so on. there are your friends, they are faster than C++ gaybo functions.
Personally, I much prefer the robustness of the C++ string object over error prone C string libraries as it means I can spend more time actually programming rather then fixing memory related bugs.
Also, not all C string library functions are faster then the C++ counterparts. One example is working out the string length. Depending on the implementation, strlen will iterate through each character of a string until it hits '\0' to work out the length of a string whereas the C++ string object will just return its cached value.
avansc wrote:
there are many str functions in C, strcmp() strcat() and so on. there are your friends, they are faster than C++ gaybo functions.
Personally, I much prefer the robustness of the C++ string object over error prone C string libraries as it means I can spend more time actually programming rather then fixing memory related bugs.
Also, not all C string library functions are faster then the C++ counterparts. One example is working out the string length. Depending on the implementation, strlen will iterate through each character of a string until it hits '\0' to work out the length of a string whereas the C++ string object will just return its cached value.
yeah i can tell its you first post.
firstly, C String library is bug free. secondly, the reason you have so many memory related bugs is because you dont program enought.....
lastly, i dont think using strln as major c string function is a good example. if you wanna go that route, everytime C++ strings updates the string you end up having to update that cashe value, wasting time, and resources.
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
I agree the C string library is bug free, however it is far more acceptable to usage errors then the C++ string library and because it requires memory allocation management on the part of the user, it can lead to subtle errors such as buffer overruns and memory stomps which can be extremely hard to debug if the crash happens and the debugger points you at a line of code nowhere near the actual cause.
In addition, having to keep track of how long your char buffer needs to be to store a particular string or any string that gets passed in can be extremely troublesome (at this point, I would suggest using the strn* version of the string functions to prevent buffer overruns).
There is also an error with your newStr function as it only copies the pointer address of char *, not the string data it is pointing to and it the memory it allocates should be 1 more then the string length to store the NULL terminator. It should be:
^ i'll have to check on that. im not sure about that.
you make good points though.
yeah your right. i kinda feel imbarrased i made such a big mistake. i think i copied code that was just inline that worked. but yeah, my func def as it is does not work. thanks for pointing that out.
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
The address to the memory that was allocated has now been lost as both temp and str are pointing to the same string and neither are pointing to the malloc'ed memory.
The address to the memory that was allocated has now been lost as both temp and str are pointing to the same string and neither are pointing to the malloc'ed memory.
i check it, it was fine. i was just lazy/forgetful when i copied in here.
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
Wow... I had the hardest time with C strings. I remember in my C class I glazed over (read: slept through) several of the MANY lectures on strings, and boy was that a mistake. I spent more time pounding my head against the keyboard with string related errors than I'd like to remember.
A cool thing about modern compilers is how they optimize everything. For instance, MSVS uses the same address space for identical data, in the case of c strings. All of the variables below point to the same address, as the code would show:
Thanks Marauder. Like I say: "you learn something everyday"
I've picked this up from messing around with pointers and stuff. I was trying to write a memory manager not too long ago for a game I'm working on (I'll get back to it when school is done in about a week and a half).
There are a slew of hidden little facts like these in my ebook collection (I know you frown about this stuff Marauder, so sorry ahead of time) Come to think about it, I'm in the process of uploading all my stuff onto an ftp server of mine. If you guys want I'll post a link to it when I'm done uploading; its taking forever though, since my hosting service limits the upload bandwidth to 60kb/s, fucking fucks!
On that note, anyone know of a hosting service that doesn't limit upload bandwidth for ftp? I'm using hostmonster for my web-side stuff.