Abhiram mishra
Abhiram mishra

Reputation: 1617

code compiles fine on stlport_shared but not on gnustl_shared

namespace MN{
  template<class _Kn> inline const _Kn& max(const _Kn& _M, const _Kn& _N)
    {return (_M < _N ? _N : _M); }
}

The above code compiles fine when I have the APP_STL := stlport_shared but when I set APP_STL := gnustl_shared , it fails with the below message.

error: expected ',' or '...' before numeric constant at line 2 In function 'const _Kn& MN::max(const _Kn&)':error: '_N' was not declared in this scope.

Not a c++ geek , please help

Upvotes: 1

Views: 132

Answers (1)

cdhowie
cdhowie

Reputation: 169143

Names starting with _ and an uppercase letter are reserved for compiler, standard library, and STL internal details. Based on the error message, it looks like gnustl has defined _M as a macro that is expanding to something you don't intend. Note that the function prototype in the error message is missing the second parameter, which hints that the preprocessor is turning _M into something else.

In general, you can avoid these kinds of problems by never using any names starting with an underscore. If you rename them to omit the underscores you should see the problem go away.

template<class Kn> inline const Kn& max(const Kn& M, const Kn& N)
  {return (M < N ? N : M); }

Further reading: What are the rules about using an underscore in a C++ identifier?

Upvotes: 3

Related Questions