Squirrel syntax anomaly?

I’ve noticed (through a bug squashing session) that the following two pieces of squirrel produce a different result while I assumed they would not. The root cause of the bug was a typo as I wouldn’t on purpose use this kind of syntax, but one that for instance in C would not make a difference.

Is this normal ? What are the rules in squirrel wrt space separation for arithmetic operators ?

sunsethr <- 18;
sunsetmin <- 12;
server.log(format("%x",sunsethr * 65536 + sunsetmin * 256));
server.log(format("%x",sunsethr *065536 + sunsetmin * 256));

this produces the following output :

2018-10-19 21:58:26 +02:00 [Agent] 120c00
2018-10-19 21:58:26 +02:00 [Agent] 7989c

The leading zero implies the number will be octal - see https://developer.electricimp.com/squirrel/squirrelcrib

This is identical to C, in fact. See https://en.cppreference.com/w/cpp/language/integer_literal

#include <stdio.h>
int main(int argc, char* argv[]) {
    printf("%x\n", 065536);
    return 0;
}

running that gives:

6b5e

thx. I learned something here. Could be a nasty to find bug if you’re not aware that 012 isn’t the same as 12…

There are 10 types of people, those that understand binary and those that don’t :wink: