Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

VC++ 6 halts after running a function

Status
Not open for further replies.

ahmed osama

Full Member level 6
Full Member level 6
Joined
Jul 18, 2004
Messages
352
Helped
2
Reputation
4
Reaction score
0
Trophy points
1,296
Location
Cairo, Egypt, Egypt
Activity points
2,652
hi all

VC++ halt each time i run the following function .....

the function ends without any error but VC++ halt after it finish ..

test ()
{
char* temp=new char [4] ;
temp="123";

__asm
{

pushad;
pushfd;
mov edx,temp;
popfd;
popad;
}

delete [] temp;


}




Any one know whyyyy !!!
 

Re: VC++ 6 halt !!!!!!!!

Your code crash on 'delete' operator!!!

Try this ...

Code:
// template declaration for 'strcpy' function
#include <string.h>

test () 
{ 
char* temp=new char [4] ; 


// with ... 
// temp="123"; 
// you REassign to 'temp' the pointer of static ARRAY "123" ... 
// you don't copy the string "123" in te allocated memory!!!
// ... 
// and you lose the previous address of memory allocated with 'new' operator 
// and thus you can't DELETE it ... ;o)

// to copy the string "123" in a 'temp' array allocated with operator 'new' use ...
strcpy(temp,"123");


__asm 
{ 

pushad; 
pushfd; 
mov edx,temp; 
popfd; 
popad; 
} 

delete temp; 


}

or simply ...

Code:
test () 
{ 
// if you don't need of dinamic allocation ... this alloc the array on the stack
char temp[]="123"; 

__asm 
{ 

pushad; 
pushfd; 
mov edx,temp; 
popfd; 
popad; 
} 

// and free the memory when it loses the visibility
}

bye ... m!k27
 

Re: VC++ 6 halt !!!!!!!!

u are right

I fixed the code but still VC++ halt when i call this func and sometime even if i didn't call it !!!!!!!!!!!!

i notice when I remove the asm part , it doesn't halt

test()
{
char* temp=new char [3] ;
temp[0]='1';
temp[1]='2';
temp[2]='\0';
__asm
{
pushad;
pushfd;
mov edx,temp;
popfd;
popad;

}

delete [] temp;
}
 

Re: VC++ 6 halt !!!!!!!!

I tryed this code on my VisualC++ 6.0 SP6 (in a Win32 console application) ... and work fine ... it must work ;o)

Code:
// have you this include?
#include <malloc.h>

int test() 
{ 
   char* temp=new char [3] ; 
   //check for NULL ptr ... if 'new' don't work ... 
   if(temp==NULL) return -1;
   temp[0]='1'; 
   temp[1]='2'; 
   temp[2]='\0'; 

__asm 
{ 
pushad; 
pushfd; 
mov edx,temp; 
popfd; 
popad; 
} 

   delete temp; 
   return 0;
}


int main (int argc, char **argv)
{

   test();
   return 0;

}

perhaps there is a problem also before the call to 'test' functinon (?) ... send other part of source ... where you call the 'test' function ... if you want

bye ... m!k27
 

VC++ 6 halt !!!!!!!!

@ahmed osama

Maybe it is program fault, try updating the software with Service Pack(SP6).
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top