Function not returning value

Hi all,
I have a function, which has to return some int data. In that function there are multiple return statements. There is also possibility that function may return in some cases. Will this result in undefined behavior???

Thanks in advance!
yup, it's all possible

if the function end without returning anything then it return undefined value

1
2
3
int p( int x ){
    if( x < 5 ) return x;
}


This is a dummy function,
anyway if you called p( 10 ) then it will return some random number
You've described this in such vague terms, it's hard to know what you really mean.

Why don't you just post the code, so we can see for ourselves?
Will this result in undefined behavior???


As rmxhaha said, it will indeed. however your compiler should issue a warning that not all paths return properly.

Btw, it's very bad to have a function like this. In fact the coding conventions in my old company forbade us to write large functions with more than one return statement.
Last edited on
Topic archived. No new replies allowed.