Tuesday, October 1, 2013

why does this work with Visual C++ 2005?

Newsgroup: comp.lang.c++

Subject: why does this work with Visual C++ 2005?

From: Lynn McGuire <lmc@...>

Date: Mon, 30 Sep 2013 18:45:34 -0500



Why does this work with Visual C++ 2005?



char buffer [10000];

void * test5 = & buffer;



I would think the compiler would give an error

on "& buffer", because "buffer" is the memory

address of the first element in the array, and

you can't get a memory address of a memory

address, there is no such thing. Note that

test5 and buffer do point to the same memory

address in the VC++ debugger after execution of

that line of code.



We do get a compiler error on:



char * test3 = & buffer;



And the following code compiles correctly:



char * test4 = & buffer [0];



The only thing i can think is the compiler

treats "& buffer" as "& buffer [0]" in the

void * case, assuming that is what the

programmer wanted.



Thanks,

Lynn













via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?98099-why-does-this-work-with-Visual-C-2005&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

No comments:

Post a Comment