4 ms·
Here's ImportC in action: _Static_assert(square(2) == 4, "failed"); int square(int x) { return x * 2; } 1. there is no need for constexpr keyword. An
by WalterBright 5y ago
Here's ImportC in action:
_Static_assert(square(2) == 4, "failed");
int square(int x) { return x * 2; }
1. there is no need for constexpr keyword. Anywhere a constant-expression in the C grammar appears, compile time function execution is involved.
2. `square` is forward referenced, but works fine.
- smartaz42 5y agoHmm, isn't square normally x*x?
- mhh__ 5y agoWalter actually retired years ago and replaced himself with an AI. Every now and again there are bugs, move along.
- WalterGR 5y agoMr. Bright is just using TDD. The ‘square’ function works for 2. Next he’ll generalize it to work for more values. Tests aren’t shown. ;)
- deleted 5y ago[deleted]
- WalterBright 5y agoI tested it, it worked for the one and only test case, therefore it was correct :-)