Page 1 of 1

AllocVecTags - Beginner.

Posted: Wed Aug 22, 2012 10:49 pm
by lorenko
Hi I'm a beginner can you help me?

my program crash after first allocation

this is the code:

.....
// Global vars
STRPTR *nP = NULL;
uint32 *pds = NULL;
.....
uint32 function(VOID)
{
uint32 count;
count =10;

if (!(pds = (uint32*)IExec->AllocVecTags((count * sizeof(uint32)),
AVT_Type, MEMF_SHARED,
AVT_Lock, FALSE,
AVT_ClearWithValue, 0,
TAG_END)));
{
IDOS->Printf("Alloc 1 failed\n");
return 1;
}
if (!(nP =(STRPTR*)IExec->AllocVecTags((count*sizeof(STRPTR)),
AVT_Type, MEMF_SHARED,
AVT_Lock, FALSE,
TAG_END)));
{
IDOS->Printf("Alloc 2 failed\n");
return 1;
}
........
}

Program output:

Alloc 1 failed

then program crash, the windows is impossible to close and after a few seconds the whole system freeze
(Always after any crash DSI error from OWb or other programs the whole system freeze!!!!)
thx

Re: AllocVecTags - Beginner.

Posted: Wed Aug 22, 2012 11:33 pm
by LyleHaze
WHen using
If(condition)
{
//response block here
}

it works fine.
But if you put a semicolon after the (condition) then the response block will ALWAYS execute,
no matter what the condition is.

If you remove the semicolon after the condition expression, then the returns will work as expected.

I have no idea why it crashes, but the code posted here works once the semicolon is removed.

LyleHaze

Re: AllocVecTags - Beginner.

Posted: Thu Aug 23, 2012 7:40 am
by lorenko
Ops :)
didn't notice the semicolon ..... :oops:

thank you

Re: AllocVecTags - Beginner.

Posted: Thu Aug 23, 2012 5:36 pm
by ChrisH
lorenko wrote:didn't notice the semicolon
Ah, the joys of C. Isn't it wonderful ;-P