Click here to Skip to main content
15,906,097 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Question_beginthread and calling convention __fastcall error Pin
DaviziN3-Oct-05 8:08
DaviziN3-Oct-05 8:08 
QuestionRe: _beginthread and calling convention __fastcall error Pin
David Crow3-Oct-05 9:21
David Crow3-Oct-05 9:21 
AnswerRe: _beginthread and calling convention __fastcall error Pin
Shog93-Oct-05 11:51
sitebuilderShog93-Oct-05 11:51 
GeneralRe: _beginthread and calling convention __fastcall error Pin
DaviziN3-Oct-05 20:53
DaviziN3-Oct-05 20:53 
GeneralRe: _beginthread and calling convention __fastcall error Pin
David Crow4-Oct-05 2:37
David Crow4-Oct-05 2:37 
GeneralRe: _beginthread and calling convention __fastcall error Pin
Shog94-Oct-05 6:34
sitebuilderShog94-Oct-05 6:34 
QuestionWeird compiler error Pin
Jim Crafton3-Oct-05 8:00
Jim Crafton3-Oct-05 8:00 
AnswerRe: Weird compiler error Pin
ddmcr3-Oct-05 9:17
ddmcr3-Oct-05 9:17 
Jim Crafton  wrote:
Any idea why VC7.1 doesn't flag this? I wanted the function doit() to potentially increment the pointer but NOT change it's value. So you'd see


Hello
ello


for the output of the test.

Is there a better way to accomplish this?




Look , for example we have two functions :

 void doit1( const char *g )
   {
	cout<<&g<<" ";
	cout<<g<<" ";//just for clearence
	cout<<*g;
	cout<<endl;
	g++;

   }

 void doit( const char *&g )
   {
	cout<<&g<<" ";
	cout<<g<<" ";//just for clearence
	cout<<*g;
	cout<<endl;
	g++;

    }

int _tmain(int argc, _TCHAR* argv[])
{

	char* VALUE = "Hello";

        /*(A)*/ doit1(VALUE);//should print "Hello"
	cout<<s<<endl;

	/*(B)*/ doit(VALUE);//should print "ello"
	cout<<s<<endl;
	
	return 0;
}

in case (A) when function doit1() is executed you pass to this function as avalue a pointer to char. So inside doit1() function, new const char* g object is created
and it is pointing to VALUE , so when you write g++ ,nothing happens with VALUE, only g is pointing to a new address , so when function ends.VALUE remains the same.

in case (B) when function doit() is executed you pass to this function a reference to pointer to char. So inside doit() no objects are cerated and you are operating straight with the address of VALUE , so when you write g++ , VALUE-s address changes and therefore when function ends "ello" is printed.

clear?? Smile | :)




"Success is the ability to go from one failure to another with no loss of enthusiasm." - W.Churchill



-- modified at 15:19 Monday 3rd October, 2005
GeneralRe: Weird compiler error Pin
Jim Crafton3-Oct-05 9:22
Jim Crafton3-Oct-05 9:22 
GeneralRe: Weird compiler error Pin
ddmcr3-Oct-05 9:30
ddmcr3-Oct-05 9:30 
QuestionReadDirectoryChangesW Pin
Klempie3-Oct-05 7:59
Klempie3-Oct-05 7:59 
QuestionRe: ReadDirectoryChangesW Pin
David Crow3-Oct-05 9:24
David Crow3-Oct-05 9:24 
AnswerRe: ReadDirectoryChangesW Pin
Klempie3-Oct-05 10:00
Klempie3-Oct-05 10:00 
Questionopen new dialog Pin
hamavreg3-Oct-05 6:19
hamavreg3-Oct-05 6:19 
AnswerRe: open new dialog Pin
bugDanny3-Oct-05 6:34
bugDanny3-Oct-05 6:34 
AnswerRe: open new dialog Pin
Prakash Nadar3-Oct-05 6:38
Prakash Nadar3-Oct-05 6:38 
AnswerRe: open new dialog Pin
ddmcr3-Oct-05 7:09
ddmcr3-Oct-05 7:09 
Questionaccess violation in release mode Pin
valerie993-Oct-05 6:02
valerie993-Oct-05 6:02 
AnswerRe: access violation in release mode Pin
Prakash Nadar3-Oct-05 6:32
Prakash Nadar3-Oct-05 6:32 
Generalyes, the dialog window Pin
valerie993-Oct-05 7:28
valerie993-Oct-05 7:28 
AnswerRe: access violation in release mode Pin
Nynaeve3-Oct-05 6:49
Nynaeve3-Oct-05 6:49 
QuestionShared Memory - Old References Pin
sweep1233-Oct-05 5:53
sweep1233-Oct-05 5:53 
Questiontrigger events Pin
Anonymous3-Oct-05 5:46
Anonymous3-Oct-05 5:46 
QuestionThe amazing vanishing keypress Pin
hairy_hats3-Oct-05 5:29
hairy_hats3-Oct-05 5:29 
AnswerRe: The amazing vanishing keypress Pin
icabod3-Oct-05 5:55
icabod3-Oct-05 5:55 

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.