Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

sepples

Name: Anonymous 2009-01-19 18:16

Hey /prog/
I never really used C or C++ before, other than when I started learning programming. I want to do something in one of them, (maybe an OS lol) but I'm not very confident about allocating/freeing up memory (I haven't done it before often).
Just to refresh my memory, as long as I use malloc and free with C and new and delete keywords with C++ I'm safe, right? And can I use malloc and free in C++ too?

Also, discuss Objective-C and the Sepplesox I heard about before.

Name: Anonymous 2009-01-19 19:43

>>31
How do you think strlen works? It simply iterates over the string while counting chracters, until it finds a null byte. It's called ASCIIZ. strlen returns the length of the actual string, not the amount of memory you need to store it. The amount of memory you need to store it is length+1( including the ending null, otherwise, if you don't include it, strlen would go on counting, and may as well count into other memory on the heap(or wherever you allocted your string) which may be completly unrelated to your string)).

( example: int pesudo_strlen(char *s)(char *s){char *p=s;while(*p)p++;return p-s;} )

Also, in your example,
 char lel[] = "wat";
The string will be statically allocated, so the compiler may place more than one null byte after it, for alignment purposes.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List