Go Down

Topic: Base prefix notation (Read 2 times) previous topic - next topic

MichaelMeissner


0bnnnnnnnn is C/C++


No it isn't.  It is a Gnu extension.


If you want to be "proper", use 0bnnnnnnnn.

If you want to be proper, use hexidecimal (0x followed by 0..9, a..f, or A..F) or octal (0 followed by 0..7).

MarkT


As for a leading zero for octal: I doubt that a worse piece of design in programming language syntax exists anywhere. Except maybe for those programming languages which number the months of the year from 0 to 11 (such as C and ECMAScript).


Let's see: I believe that the relevant rule in many programming languages (including the Arduino programming environment) goes like this:
Numbers with only decimal digits (0 through 9) are decimal.
Except if they begin with 0, in which case they are octal.
Except if they contain a decimal point, in which case they are decimal after all.
Please correct me if I am wrong.


except if they contain a decimal point or an exponent, I think.   02e4 = 20000.0
[ I won't respond to messages, use the forum please ]

odometer

#22
May 04, 2013, 05:04 am Last Edit: May 04, 2013, 05:12 am by odometer Reason: 1

Quote

As for zero-origin indexing: following your logic, why aren't the days within each month numbered starting from zero?

Because they are already numbered.

As are the months of the year.

Really, who understands month "1" to be February but a programmer, and then only in the context of source code?
Woe to that programmer if s/he uses that month numbering in a user interface...

majenko



Quote

As for zero-origin indexing: following your logic, why aren't the days within each month numbered starting from zero?

Because they are already numbered.

As are the months of the year.

Really, who understands month "1" to be February but a programmer, and then only in the context of source code?
Woe to that programmer if s/he uses that month numbering in a user interface...

That's why 8 out of 10 cats prefer strftime()...
Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

JosAH


Quote

int c3=076; <--- This is troublesome
int c4=098; <--- Ahhhh!!!!!! (actually throws a compiler error!)


I don't know why it always makes me crack up, but I love this comment in the 2nd edition of K&R:
Quote

Everyone's favorite trivial change: 8 and 9 are not octal digits


So pre-ANSI, your 098 might not have thrown an error, but I have no idea what it would do.


Those old compilers (from the mid 70s of the previous century) just considered, say, 099 to be equal to 8*9+9 == 81.

kind regards,

Jos

Go Up