Error: invalid digit "9" in octal constant?


#1

Hello!

I am getting a weird error for an array with some values in. When I put 09, zero nine, into the array I get the error. This is the array:

int Array[32] {
00,04,05,00,-1,-3,00,04,-8,-7,12,00,-1,04,-3,05,
00,04,02,03,-1,-3,09,01,-8,-7,12,00,-1,04,-3,05
};

This is the error I am getting:
/Users/jakobskouborg/Documents/axoloti/build/xpatch.cpp:451:25: error: invalid digit "9" in octal constant
00,04,02,03,-1,-3,09,01,-8,-7,12,00,-1,04,-3,05

Why could that be? Am i breaking some coding convention by adding a zero, so there is always 2 digits in a number? Like 01, 02, -5, 06, etc.

All the other digits in the array works fine, only the 09 is an issue.

Thanks!


#2

thats C for you :slight_smile:

so 0 prefix - means Octal (base 8 ), 0x means hex (base 16)

https://www.includehelp.com/c/octal-literals.aspx


#3

Ahh Thanks, I will look into it :slight_smile:

I just needed some arrays with varying digit numbers to allign under each other, visually, so I tried it and than 09 seemed to mess it up :slight_smile:

Need to try something else then :slight_smile:


#4

oh to add , why octal?

i think basically because we often want to use binary, but binary numbers are pretty hard to type accurately,
hex is a little difficult to translate to binary (unless you do it very frequently) ...but octal is really easy e.g. we all now 7=111, 6 is 110 - its actually really useful. ( * )

( i think 0b prefix for binary was added a bit later.. in c++, not sure if C supports it ?)

I use spaces, all program editors should be using monospace...
hmm, not sure about axoloti :confused: as i tend to type axo code in another editor, I guess it must be otherwise code indentation wouldn't work too well ?!

can't think off the top of my head of another character to use.


( * ) hmm, something ive never thought of... I should 'learn/practice' the translation from hex <-> oct, that should be trivial - and would actually mean I could do hex<-> binary really easily ... wow that could be very handy!


#5

Ahh yes that might do the trick :slight_smile:

I am doing sequencing straight from arrays without any interface or UI elements, I just set the value in the arrays, like this

bool Array[1024] {
1,00,00,01,00,00,00,00,01,00,01,00,00,00,01,00 };

Just to try a different way. And then I wanted some arrays for pitch values, where I need the bigger values and when I tried that the 09 problem occurred. But yeah, spaces will do the trick too I guess :slight_smile: