warning while adding element

For developers writing C++, Fortran, Java, code who have questions or comments to make.

Moderators: silvia, selimgunay, Moderators

Post Reply
eroz
Posts: 49
Joined: Wed Sep 14, 2005 7:47 am
Location: San Francisco

warning while adding element

Post by eroz »

Adding a new zero-length element with name: "MyElement". Compiles but gives the warning:

warning C4715: 'MyElement::commitState' : not all control paths return a value

Couldn`t make out what the warning implies. Any help is appreciated. Thanks.
aneeman
Posts: 90
Joined: Thu Jan 12, 2006 1:13 pm
Contact:

Re: warning while adding element

Post by aneeman »

The function prototype for commitState is
int commitState( )
so you need to return an integer value. You probably have some if statements, like

if ( do stuff successfully )
return ( number that signals success );

but there are ways to go through your function and never get to the "return" part.

So you could add a last line to the function

return (some number that means there was a mistake);

cheers,
alisa
eroz wrote:Adding a new zero-length element with name: "MyElement". Compiles but gives the warning:

warning C4715: 'MyElement::commitState' : not all control paths return a value

Couldn`t make out what the warning implies. Any help is appreciated. Thanks.
eroz
Posts: 49
Joined: Wed Sep 14, 2005 7:47 am
Location: San Francisco

Post by eroz »

Thanks for the response. Isn`t what I have below supposed to increase "code" if (successfull) and return an error message if (unsuccessfull), thus cover both cases if the function is successfull or not? Thanks.

Here is what I have:
int ZeroLength::commitState()
{
int code=0;

// call element commitState to do any base class stuff
if ((code = this->Element::commitState()) != 0)
{
opserr << "MyElement::commitState () - failed in base class";
}


// commit 1d materials
for (int i=0; i<numMaterials1d; i++)
{ code += theMaterial1d->commitState();
return code;
}
}
aneeman
Posts: 90
Joined: Thu Jan 12, 2006 1:13 pm
Contact:

Post by aneeman »

eroz wrote:Thanks for the response. Isn`t what I have below supposed to increase "code" if (successfull) and return an error message if (unsuccessfull), thus cover both cases if the function is successfull or not? Thanks.

Right idea, you just need to return code *after* the loop.

Here is what I have:
int ZeroLength::commitState()
{
int code=0;

// call element commitState to do any base class stuff
if ((code = this->Element::commitState()) != 0)
{
opserr << "MyElement::commitState () - failed in base class";
}


// commit 1d materials
for (int i=0; i<numMaterials1d; i++)
{ code += theMaterial1d->commitState();
return code;
}
// You should return code here, and the value will
//be the sum of the number of errors.
}
eroz
Posts: 49
Joined: Wed Sep 14, 2005 7:47 am
Location: San Francisco

Post by eroz »

Got it; thanks again!
Post Reply