News for hackers. Stuff that matters.
Re:C for All by emilfihlman on Friday March 23, 2018 @07:11PM (#16663464)
Exponentiation operator gratuitous and unnecessary?

WHAT?

Re:C for All by kragen on Friday March 23, 2018 @07:49PM (#16663671)
It doesn't improve readability. Compare:

   discrim = b² - 4ac;                  // Standard notation
   float discrim = pow(b, 2) - 4*a*c;   // C
   float discrim = b \ 2 - 4*a*c;       // C∀
I would argue that these are presented here in descending order of readability.

Also its typing rules are really complicated; apply it to two integers and magically you are thrown into the floating-point world where you can never be completely certain of anything, but if you use an unsigned exponent then you stay safely in integer-land.

Re:C for All by dom96 on Friday March 23, 2018 @09:50PM (#16664285)
The choice of operator seems very odd to me. Wouldn't `^` be significantly more readable?
Re:C for All by userbinator on Friday March 23, 2018 @09:55PM (#16664307)
^ is already used for bitwise xor.
Re:C for All by earenndil on Friday March 23, 2018 @10:30PM (#16664434)
What about then, like some other languages?
Re:C for All by Amelorate on Friday March 23, 2018 @10:56PM (#16664525)
Python uses * * , but that is ambigous with

  int a = 1;
  int *b = &a;
  int c = a ** b;
  // Am I casting b to an int (returning it's address) and exponenting it or am I derefrencing b and multiplying it's result with a?
Re:C for All by wkz on Saturday March 24, 2018 @02:49PM (#16668147)
How would this be different from &? It is also a unary operator and && is a different binary operator.

'||' and '&&' are distinct tokens in C as far as i know, i.e. not handled as two consecutive '|'s or '&'s.

So your example would unambiguously be parsed as "a to the b:th power". Whereas the other case would need explicit parens:

   int c = a * (*b);
Similar example for &:

   int a = 1;
   int b = 1 && a; /* 1 LOGICAL_AND a */
   int c = 1 & (&a); /* 1 AND address of a */
Re:C for All by mafuy on Tuesday March 27, 2018 @05:27PM (#16692887)
Just dropping in to say you are completely correct. It is called "maximum munch" and mandated by the C spec. I recently wrote a toy C compiler and was confused until I learned this.
Re:C for All by userbinator on Friday March 23, 2018 @11:25PM (#16664653)
I suppose ^^ might work, although a little odd because by consistency it would otherwise be the "logical XOR", a mythical operator that doesn't actually make much sense.
Re:C for All by poizan42 on Saturday March 24, 2018 @06:16AM (#16665849)
> a mythical operator that doesn't actually make much sense.

Hmm I'm pretty sure practically every programming languages have it. It usually looks like "!=" or "<>".

The even more obscure logical XNOR is usually denoted "==" or "="

Re:C for All by kazagistar on Saturday March 24, 2018 @11:33AM (#16667094)
Alas, this doesn't deal with the idea of truthyness as a proper logocal XOR would, so it is incorrect in many of the most popular languages, including C, where a value that is true is not always equal to another value that is true. This only works in the much more strongly typed languages, or when you force cast both sides to a boolean with something like !!
Re:C for All by opejn on Saturday March 24, 2018 @12:50PM (#16667504)
Yes! In C its full spelling is "!a != !b".
Re:C for All by danharaj on Saturday March 24, 2018 @09:53AM (#16666587)
Not quite..
Re:C for All by theOnliest on Saturday March 24, 2018 @08:26AM (#16666274)
Perl has logical xor, which is occasionally useful. I usually reach for it when argument checking, where it makes sense to have either this param or that but not both.
Re:C for All by kbenson on Friday March 23, 2018 @10:54PM (#16664514)
> What about then, like some other languages?

I assume there's a double asterisk there, and it's being eaten by the formatter?

Re:C for All by earenndil on Saturday March 24, 2018 @12:50AM (#16664934)
Right yes. I forgot to escape, and now it's too late to.
Re:C for All by vanderZwan on Saturday March 24, 2018 @05:54AM (#16665782)
Probably too much ambiguity with pointers
Re:C for All by dzdt on Saturday March 24, 2018 @10:47AM (#16666823)
Idiomatic C would say:

  float discrim = b*b - 4*a*c;
Using pow for a small integer power is a no-no: less efficient and less accurate.

I agree that \ is an awkward choice. A Fortran-like double asterisk ∗∗ is out because of ambiguity with pointers; single caret ^ out because it is already reserved for bitwise xor. Maybe double caret ^^ or asterisk-caret ∗^ could be used? That would read okay :

  double discrim = b^^2 - 4*a*c;
  double discrim = b*^2 - 4*a*c;
Re:C for All by jcelerier on Saturday March 24, 2018 @12:07PM (#16667293)
> Using pow for a small integer power is a no-no: less efficient and less accurate.

Using pow for a small integer power compiles into the exact same code: https://godbolt.org/g/CjoHdJ

Re:C for All by stochastic_monk on Saturday March 24, 2018 @03:59PM (#16668565)
Only for 1 or 2, unless you turn on --fast-math.
Re:C for All by tejasmanohar on Sunday March 25, 2018 @04:08PM (#16674269)

  Using pow for a small integer power is a no-no: less efficient and less accurate.
I think you missed the point.