4 ms·
What’s the problem with *? Do you just want a different symbol or an entirely different syntax?
by echoangle 2y ago
What’s the problem with *? Do you just want a different symbol or an entirely different syntax?
- flohofwoe 2y agoNot the OP, but the '*' is already the common symbol for multiplication. Not much of a problem for people who are used to C syntax of course, but may be confusing to anybody else, especially in expressions which have both pointer dereference and multiplication, for instance this is entirely valid C: int a = 3 ** int_ptr; The '^' is the pointer symbol in Pascal, so it's not a new thing either, it just fell a bit out of fashion.
- Y_Y 2y agoThat's horrifying, I think I would have preferred int a = powl(3,int_ptr); edit: The parent's code does a dereference and then a multiplcation. This is because of (imho) bizarre parsing rules for a dereference asterisk. I'm saying that's so horrifying that I would be less horrified if it really was an exponent (as it might seem by mixing languages).
- echoangle 2y agoI’m not sure I understand your comment, wasn’t the point that int a = 3 ** int_ptr; Calculates 3 times (*int_ptr)?
- AlexeyBrin 2y agoIt was a confusion between ** used as the rise to power operator in languages like Fortran or Python which just validated the grandparent point of confusing syntax for people not used with C that come from other programming languages. In Python and Fortran for example: 3 ** 2 = 9
- flohofwoe 2y agoSee, it is confusing, because the code doesn't compute a power. It's a multiplication with the value pointed to by int_ptr, e.g. rewritten to make more sense: int a = 3 * (*int_ptr); ...or in Odin it would look like this (I think, haven't used Odin all that much yet): a := 3 * int_ptr^
- jpc0 2y agoThat's not what the code does. 3 ** int_ptr multiplies the vakue pointed at by int_ptr by 3. It is exactly the same code as 3 * (*int_ptr) which is the point the parent was making. powl(3, int_ptr) would be (int)int_ptr * (int)int_ptr * (int)int_ptr which is also unlikely what you wanted. You probably wanted to say powl(3, *int_ptr) EDIT: actually even my last paragraph is wrong because the first arg is base... I'm not going to write it out but you get the point...
- Izkata 2y agoRelated: I like the "down to" operator: https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c https://stackoverflow.com/questions/1642028/what-is-the-oper... (No, it's not a real operator, it's another case of weird but allowed spacing causing confusion)