mpflanzer commented on code in PR #19891: URL: https://github.com/apache/nuttx/pull/19891#discussion_r3798148787
########## include/cxx/bits/std_abs.h: ########## @@ -0,0 +1,64 @@ +//*************************************************************************** +// include/cxx/bits/std_abs.h +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. The +// ASF licenses this file to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance with the +// License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations +// under the License. +// +//*************************************************************************** + +#ifndef __INCLUDE_CXX_BITS_STD_ABS +#define __INCLUDE_CXX_BITS_STD_ABS + +//*************************************************************************** +// Included Files +//*************************************************************************** + +#include <nuttx/config.h> +#include <stdlib.h> + +#undef abs + +//*************************************************************************** +// Namespace +//*************************************************************************** + +namespace std +{ + using ::abs; + + constexpr float abs(float x) Review Comment: Maybe I\m overlooking something but I don't see how that would work. There is already a `using ::abs` in the `cstdlib` file: https://github.com/apache/nuttx/pull/19891/changes#diff-5ff7e243def7803a15dfe08657a5be4696307401d71b0c9acf2d117f63642312R114 The problem is that nothing defines `float abs(float)`, `double abs(double)` and `long double abs(long double)` yet. In C the floating point functions are called `fabsf`, `fabs` and `fabsl`. Without no overloading in C the only definition for `abs` is `int abs(int)`. So `using ::abs` will only make this available as `std::abs`. On the other hand in C++ `std::abs` is overloaded for floating point types. As far as I'm aware the only option is to define the functions with the respective argument and return types. ########## include/cxx/bits/std_abs.h: ########## @@ -0,0 +1,64 @@ +//*************************************************************************** +// include/cxx/bits/std_abs.h +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. The +// ASF licenses this file to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance with the +// License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations +// under the License. +// +//*************************************************************************** + +#ifndef __INCLUDE_CXX_BITS_STD_ABS +#define __INCLUDE_CXX_BITS_STD_ABS + +//*************************************************************************** +// Included Files +//*************************************************************************** + +#include <nuttx/config.h> +#include <stdlib.h> + +#undef abs + +//*************************************************************************** +// Namespace +//*************************************************************************** + +namespace std +{ + using ::abs; + + constexpr float abs(float x) Review Comment: Maybe I'm overlooking something but I don't see how that would work. There is already a `using ::abs` in the `cstdlib` file: https://github.com/apache/nuttx/pull/19891/changes#diff-5ff7e243def7803a15dfe08657a5be4696307401d71b0c9acf2d117f63642312R114 The problem is that nothing defines `float abs(float)`, `double abs(double)` and `long double abs(long double)` yet. In C the floating point functions are called `fabsf`, `fabs` and `fabsl`. Without no overloading in C the only definition for `abs` is `int abs(int)`. So `using ::abs` will only make this available as `std::abs`. On the other hand in C++ `std::abs` is overloaded for floating point types. As far as I'm aware the only option is to define the functions with the respective argument and return types. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
