I often switch between languages, and often confuse myself if lists start at 0 or 1.
Because it will throw an array out of bounds error on zero, could it perhaps throw a warning at compile time?
ID:1430790
Nov 26 2013, 1:31 pm
|
|||||||
| |||||||
Nov 27 2013, 9:38 am
|
|
This isn't something you'll typically know at compile-time. But when you are hard-coding an index, an error would make sense for anything that couldn't possibly be in bounds; a warning would not. I don't know how feasible this is.
|
I think it's safe to assume that if the user types in something like
if (index[0] == 1) The compiler would warn the user that 0 (and below) is not an acceptable index. Not sure how possible this would be using iterative indices (i.e. for var/i = 0 to 9) |
In response to Makeii
|
|
Makeii wrote:
I think it's safe to assume that if the user types in something like I agree. Should it be a warning or an error? I would think it would be considered a warning, due to it still technically compiles, it would just result in a runtime error. |
Might as well make it an error, but consistently it wouldn't do well, considering using variables and iterative values wouldn't be caught by the compiler. If you're not certain, you can always define something for yourself. Just throwing this out there:
#define LI 1 |