About Store Forum Documentation Contact



Post Reply 
Why warning?
Author Message
Babulesnik Offline
Member

Post: #1
Why warning?
I wrote a function:
Code:
Int IndexMOC(Str Socket)
{
    FREP(server.clients.elms())
    {
        if(Equal(server.clients.lockedElm(i).key.asText(),Socket))
        return i;
    }
}

Get a warning:
Warning 4 warning C4715: 'IndexMOC' : not all control paths return a value c:\documents and settings\дима\рабочий стол\project_fast_games\project\server\server_lib.h 181
03-15-2011 05:42 PM
Find all posts by this user Quote this message in a reply
Tottel Offline
Member

Post: #2
RE: Why warning?
I'm not an expert, but it only returns something (i) when the if statement is true. If it's not, it doesn't return anything, so you may want to return -1 or 0 or something when your if-statement is false.
(This post was last modified: 03-15-2011 05:58 PM by Tottel.)
03-15-2011 05:58 PM
Find all posts by this user Quote this message in a reply
Chris Offline
Member

Post: #3
RE: Why warning?
Add a fail case, and handle it accordingly whenever you call the function - else its not a good coding practice:

[quote='Babulesnik' pid='21907' dateline='1300207339']
I wrote a function:
Code:
Int IndexMOC(Str Socket)
{
    FREP(server.clients.elms())
    {
        if(Equal(server.clients.lockedElm(i).key.asText(),Socket))
        return i;
    }
    return -1;
}
03-15-2011 06:30 PM
Find all posts by this user Quote this message in a reply
Babulesnik Offline
Member

Post: #4
RE: Why warning?
(03-15-2011 06:30 PM)Chris Wrote:  Add a fail case, and handle it accordingly whenever you call the function - else its not a good coding practice:

[quote='Babulesnik' pid='21907' dateline='1300207339']
I wrote a function:
Code:
Int IndexMOC(Str Socket)
{
    FREP(server.clients.elms())
    {
        if(Equal(server.clients.lockedElm(i).key.asText(),Socket))
        return i;
    }
    return -1;
}

Thank you very much.
03-15-2011 07:32 PM
Find all posts by this user Quote this message in a reply
Post Reply