This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Returning a reference to local function parameters


Hi,

does anyone know why the following peace of code compiles without warning?:

int& max(int x, int y)
{
    return (x < y)? y: x;
}

I would expect a warning message like "warning: reference to local
variable... returned", but there isn't any warning.
I can only guess that it is a runtime decision which reference to which
variable should be returned. But why can't gcc take care of it and
doesn't print a warning message like the above one?

Thanks in advance,
Steve

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]