[PATCH] Move mod calculations to a separate helper
Linus Torvalds
torvalds at linux-foundation.org
Wed May 21 14:11:17 PDT 2014
On Wed, May 14, 2014 at 8:44 PM, Anton Lundin <glance at acc.umu.se> wrote:
>
> I went a little bit hard on trying to use proper units so this code
> doesn't build on older compilers anymore, but we could go a bit less
> haywire on the types and apply something like this.
The problem wasn't that you used proper types, the problem was that
you used much-too-recent C++ features.
Instead of using a cast initializer in a return statement, use a real
variable. So something like
return (depth_t) { .mm = po2_limit.mbar * 1000 / get_o2(mix) *
10 - 10000 };
requires compilers to support a cast-initializer (whatever it is
called) in an expression, but
depth_r depth = { .mm = po2_limit.mbar * 1000 / get_o2(mix) *
10 - 10000 };
return depth;
will just work with any compiler that supports named initializers. And
for *really* old compilers you could even have done
depth_t depth;
depth.mm = ...
return depth;
but I don't think we need to care about anything that predates named
structure initializers (we use them elsewhere already).
The "(type) { .. }" syntax is special and while denser, not really
universally supported as you found out (as usual supported by random
pre-standard compiler versions)
Linus
More information about the subsurface
mailing list