Vinoth Karthick
Vinoth Karthick

Reputation: 1087

g++ compilation error on AIX unix server

I have a socket program server code written in C++.

I'm facing the below error when it is compiled using g++ compiler(OS : Unix AIX). The same code compiled successfully using cc compiler(OS : Unix Sun OS ). Please let me know how to resolve it.

Using built-in specs.

COLLECT_GCC=g++

COLLECT_LTO_WRAPPER=/opt/freeware/libexec/gcc/powerpc-ibm-aix7.1.0.0/4.8.2/lto-wrapper

Target: powerpc-ibm-aix7.1.0.0

Configured with: ../gcc-4.8.2/configure --with-as=/usr/bin/as --with-ld=/usr/bin/ld --enable-languages=c,c++,fortran --prefix=/opt/freeware --mandir=/opt/freeware/man --infodir=/opt/freeware/info --enable-version-specific-runtime-libs --disable-nls --enable-decimal-float=dpd --host=powerpc-ibm-aix7.1.0.0

Thread model: aix

gcc version 4.8.2 (GCC)

Upvotes: 2

Views: 522

Answers (2)

n. m. could be an AI
n. m. could be an AI

Reputation: 119877

Don't do this regardless of whether there's an error. These are enumerators of type std::ios_base::openmode and you want to use this type, not your own enum type. If you really do want to rename/alias standard library entities:

namespace sockStates
{
  static const ios::openmode
      inopen  = ios::in,
      outopen = ios::out,
      open    = ios::in | ios::out;
};

I would not recommend this though. Just use ios::in | ios::out explicitly wherever. An average C++ programmer knows immediately what this means.

Upvotes: 1

Jonathan Wakely
Jonathan Wakely

Reputation: 171263

The problem is that GCC's standard library defines std::ios::openmode as an enumeration type with overloaded operators, and in C++03 those operators are not allowed to appear in a constant expression (such as the initializer for an enumerator).

It works with the Solaris compiler because (I assume) openmode is just an integral type. The standard allows either, so both compilers are conforming.

In C++11 mode the operators are constexpr and can be used here, so one solution is to compile with -std=c++11 or -std=gnu++11, but be aware that the ABI for C++11 types is not finalised in GCC 4.8.

Another solution is to replace the enumerators with constant variables:

enum sockstates { _max = std::numeric_limits<int>::max() };

const sockstates inopen  = ios::in;
const sockstates outopen = ios::out;
const sockstates open    = ios::in | ios::out;

Upvotes: 3

Related Questions