Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Re: char * memo...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 12 of 37 Topic 43302 of 48417
Post > Topic >>

Re: char * memory leak

by "Alf P. Steinbach" <alfps@[EMAIL PROTECTED] > Feb 14, 2008 at 03:09 AM

* Travis:
> Quick question, how is a char * different than any other pointer? I've
> never had this really elaborated.

That's not a quick question.

'char' is the smallest addressable unit of memory in C and C++.

First, this means a char* pointer may on some architectures need to be 
larger than other data pointers (excluding member data pointers), and in 
effect it probably determines the size of void*, which must be large 
enough for any data pointer.

Second, it means that char* (or variants signed char* or unsigned char*) 
is the pointer type you need to use do byte-level memory addressing, 
e.g. for traversing data structures defined at the assembly level or in 
file headers.

The above two points are not entirely language-specific.  For example, 
as I recall in Turbo Pascal you had to use pChar (effectively the same 
as C++ char*) in order to do pointer arithmetic, which could not be done 
using other pointer types.  The C++ properties of char* derive from 
general considerations which probably were the same that influenced the 
design of Turbo Pascal in this regard.

Apart from that, char* in C++ is a bit more unsafe than other pointer 
types because C++ freely converts a literal string to char* instead of 
only char const*, for backwards compatibility with C, and because many 
old C functions expect char* argument instead of char const*.

Finally, due to the properties of 'char' you can in practice always 
safely reinterpret_cast a char* to an (un)signed char* and vice versa, 
although this is not directly sup****ted by the standard.  You can't do 
that in a ****table way for e.g. int*, because (disclaimer: this has been 
debated infinitely many times without a totally clear and absolutely 
convincing conclusion) int allows a trap representation.


Cheers, & hth.,

- Alf

-- 
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
 




 37 Posts in Topic:
char * memory leak
Travis <travis.bowers@  2008-02-13 16:26:03 
Re: char * memory leak
Travis <travis.bowers@  2008-02-13 16:29:38 
Re: char * memory leak
"Default User"   2008-02-14 00:39:58 
Re: char * memory leak
"Daniel T." <  2008-02-13 20:41:22 
Re: char * memory leak
"Default User"   2008-02-14 00:33:44 
Re: char * memory leak
Travis <travis.bowers@  2008-02-13 17:09:09 
Re: char * memory leak
"Default User"   2008-02-14 01:19:25 
Re: char * memory leak
"Daniel T." <  2008-02-13 20:58:10 
Re: char * memory leak
"Daniel T." <  2008-02-13 20:19:22 
Re: char * memory leak
Eric <xingshi8000@[EMA  2008-02-13 17:54:15 
Re: char * memory leak
"Daniel T." <  2008-02-13 21:13:34 
Re: char * memory leak
"Alf P. Steinbach&qu  2008-02-14 03:09:20 
Re: char * memory leak
"Default User"   2008-02-14 16:57:34 
Re: char * memory leak
"Alf P. Steinbach&qu  2008-02-14 23:39:31 
Re: char * memory leak
"Default User"   2008-02-14 23:56:47 
Re: char * memory leak
"Alf P. Steinbach&qu  2008-02-15 04:03:35 
Re: char * memory leak
Kai-Uwe Bux <jkherciue  2008-02-14 23:31:09 
Re: char * memory leak
"Alf P. Steinbach&qu  2008-02-15 05:48:41 
Re: char * memory leak
Kai-Uwe Bux <jkherciue  2008-02-15 00:05:46 
Re: char * memory leak
"Default User"   2008-02-15 17:02:32 
Re: char * memory leak
"Alf P. Steinbach&qu  2008-02-15 21:15:22 
Re: char * memory leak
"Default User"   2008-02-15 20:27:30 
Re: char * memory leak
"Alf P. Steinbach&qu  2008-02-15 21:39:09 
Re: char * memory leak
"Default User"   2008-02-15 22:01:23 
Re: char * memory leak
"Daniel T." <  2008-02-15 19:54:56 
Re: char * memory leak
"Default User"   2008-02-16 01:18:50 
Re: char * memory leak
"Alf P. Steinbach&qu  2008-02-16 03:40:26 
Re: char * memory leak
"Default User"   2008-02-17 07:30:45 
Re: char * memory leak
Kai-Uwe Bux <jkherciue  2008-02-17 02:59:28 
Re: char * memory leak
Eric <xingshi8000@[EMA  2008-02-13 18:17:29 
Re: char * memory leak
"Daniel T." <  2008-02-13 21:59:02 
Re: char * memory leak
James Kanze <james.kan  2008-02-14 03:31:50 
Re: char * memory leak
"Daniel T." <  2008-02-14 11:22:10 
Re: char * memory leak
Tobias <google@[EMAIL   2008-02-14 13:42:48 
Re: char * memory leak
Tobias <google@[EMAIL   2008-02-15 00:21:13 
Re: char * memory leak
"Alf P. Steinbach&qu  2008-02-15 09:37:31 
Re: char * memory leak
"Daniel T." <  2008-02-16 07:59:41 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Nov 21 10:38:58 CST 2008.