A
A
is it safer to write:
if (month < 1 || month > 12)
{
// month is safe here
if (day < 1 || day > monthDays[month-1]) // do something
}
rather than:
if (month < 1 || month > 12 || day < 1 || day > monthDays[month-1])
{
// do something
}
or maybe:
if ( (month < 1 || month > 12) || (day < 1 || day > monthDays[month-1]) )
{
// do something
}
in other words, is evaluation of parameters above something that is
dependent of the compiler or of the c++ standard? so that i don't get
undefined value in monthDays[month-1] if integer "month" is out of range? of
course, second and third version are easier to write but should it work
safely as far as monthDays[month-1] is considered?
if (month < 1 || month > 12)
{
// month is safe here
if (day < 1 || day > monthDays[month-1]) // do something
}
rather than:
if (month < 1 || month > 12 || day < 1 || day > monthDays[month-1])
{
// do something
}
or maybe:
if ( (month < 1 || month > 12) || (day < 1 || day > monthDays[month-1]) )
{
// do something
}
in other words, is evaluation of parameters above something that is
dependent of the compiler or of the c++ standard? so that i don't get
undefined value in monthDays[month-1] if integer "month" is out of range? of
course, second and third version are easier to write but should it work
safely as far as monthDays[month-1] is considered?