Click here to Skip to main content
15,887,476 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: string buffer Pin
George L. Jackson10-Dec-07 9:44
George L. Jackson10-Dec-07 9:44 
GeneralRe: string buffer Pin
CPallini10-Dec-07 10:42
mveCPallini10-Dec-07 10:42 
GeneralRe: string buffer Pin
George L. Jackson10-Dec-07 11:27
George L. Jackson10-Dec-07 11:27 
GeneralRe: string buffer Pin
CPallini10-Dec-07 13:22
mveCPallini10-Dec-07 13:22 
GeneralRe: string buffer Pin
George L. Jackson10-Dec-07 13:49
George L. Jackson10-Dec-07 13:49 
GeneralRe: string buffer Pin
George_George10-Dec-07 15:54
George_George10-Dec-07 15:54 
GeneralRe: string buffer [modified] Pin
George L. Jackson10-Dec-07 16:36
George L. Jackson10-Dec-07 16:36 
GeneralRe: string buffer Pin
CPallini10-Dec-07 21:44
mveCPallini10-Dec-07 21:44 
I'm a bit tired about your rather dogmatic approach (don't blame me aboutRose | [Rose] ).
First of all, you cannot pretend we're using C++. The construct works as well using C language and its C++ behavior it is probably due to C inheritance.
On this grounds you can well understand that reinterpret_cast it is out-of-the-game.
Now let's make a little test.
The following C program:
int main(int argc, _TCHAR* argv[])
{
	
	char a[]="hello world";

	char * p = a;
	char * q = &a[0];
	char * r = &a;

	printf("%x %x %x\n", p, q, r);
	getchar();
}

compiles fine.
On execution the values of the p,q,r are the same (i.e. the address of the memory containing the string "hello world") and, if you look at assembly generated, you can find:

	char * p = a;
00413392  lea         eax,[ebp-14h] 
00413395  mov         dword ptr [ebp-20h],eax 
	char * q = &a[0];
00413398  lea         eax,[ebp-14h] 
0041339B  mov         dword ptr [ebp-2Ch],eax 
	char * r = &a;
0041339E  lea         eax,[ebp-14h] 
004133A1  mov         dword ptr [ebp-38h],eax 

So your supposed inefficiency is out-of-the-game too.

Of course C++ compiler tends to be 'more strict' on type checking, but this has nothing to do with the core of the original note, that I can summarize as follows:

On a real pointer variable (e.g. char *p) the address-of-operator & as the noticeable effect of really taking the address of the variable (address of p). On the other hand, when & is applied to an array name (e.g. to the name a of the array char a[5];) it returns the same address that the array name itself returns.
In other words,

char a[5];
char *p;
p = a;
printf("p=%x, &p=%x\n); 
printf("a=%x, &a=%x\n");

produces (on my computer, maybe you'll find something quite similar on yours) the following output:
p=12ff58 &p=12ff4c
a=12ff58 &a=12ff58



As I stated above, this is the main point. That said, there are differences between a and &a, differences extensively pointed out in this thread postings and related documentation.

Smile | :)

If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.


GeneralRe: string buffer Pin
George L. Jackson11-Dec-07 0:50
George L. Jackson11-Dec-07 0:50 
GeneralRe: string buffer Pin
CPallini11-Dec-07 1:49
mveCPallini11-Dec-07 1:49 
GeneralRe: string buffer Pin
David Crow11-Dec-07 4:02
David Crow11-Dec-07 4:02 
GeneralRe: string buffer Pin
George L. Jackson11-Dec-07 4:23
George L. Jackson11-Dec-07 4:23 
GeneralRe: string buffer Pin
David Crow11-Dec-07 4:36
David Crow11-Dec-07 4:36 
GeneralRe: string buffer Pin
CPallini11-Dec-07 4:28
mveCPallini11-Dec-07 4:28 
GeneralRe: string buffer Pin
David Crow11-Dec-07 4:33
David Crow11-Dec-07 4:33 
GeneralRe: string buffer Pin
CPallini11-Dec-07 4:47
mveCPallini11-Dec-07 4:47 
GeneralRe: string buffer Pin
George_George10-Dec-07 15:32
George_George10-Dec-07 15:32 
GeneralFunction pointer Pin
George_George10-Dec-07 0:46
George_George10-Dec-07 0:46 
GeneralRe: Function pointer Pin
CPallini10-Dec-07 0:57
mveCPallini10-Dec-07 0:57 
GeneralRe: Function pointer Pin
George_George10-Dec-07 1:11
George_George10-Dec-07 1:11 
GeneralRe: Function pointer Pin
CPallini10-Dec-07 2:03
mveCPallini10-Dec-07 2:03 
GeneralRe: Function pointer Pin
George_George10-Dec-07 2:27
George_George10-Dec-07 2:27 
GeneralRe: Function pointer Pin
CPallini10-Dec-07 2:37
mveCPallini10-Dec-07 2:37 
GeneralRe: Function pointer Pin
toxcct10-Dec-07 2:39
toxcct10-Dec-07 2:39 
GeneralOK buddy! Pin
CPallini10-Dec-07 2:43
mveCPallini10-Dec-07 2:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.