Link to home
Start Free TrialLog in
Avatar of kwaldman
kwaldman

asked on

GNU G++ Compiler vs AIX xlC compiler

I'm having trouble understanding why the xlC compiler refuse
to compile code that GNU will compile.  Looking at the code
it seems to be legal C++ code.  Are different standards being used?
Thanks
Karl

--Here's my code
        I put together a simple program that demonstrates the errors.
Here's the .H.   I'm not worried about the warnings, just the things that "break" the compiler.  Ideally, we should
be able to change compilers without changing code. I know this assumes a great deal, but perhaps you can help.
Thanks
Karl
--------------------------------------------------------

#ifndef FOO_H
#define FOO_H


class foo
{
      public:
            foo();

            // Error two
            //virtual int foo_method() {}
            int foo_other_method(int );
      private:
            // Error one
            const int FOO_CONST_ONE = -1;
            static int FOO_CONST_TWO = -2;            

};


#endif

-----------------------------
Here's the .C
----------------------------
#include <iostream.h>
#include <stdlib.h>
#include "foo.H"


int main()
{
}
foo::foo()
{
      int i = 0;
      int result;

      cout << i  << endl;
      
      result = foo_other_method(i);

      cout << result;
}


int foo::foo_other_method(int i)
{

      int two = 2;
      if(i >= 1)
      {
            return two;
      }
      else
      {
            //error #3
            exit(-1);
      }
      
}
---------------------------------------------------


Here's the comipiler output under g++ and xlC
-------------------------------------------------
g++  -Wall -I. -o foo foo.C

foo.H: In method 'int foo::foo_method()';
In file included from foo.C:3:
foo.H:11: warning: control reaches end of non-void function 'foo::foo_method()'
foo.C: At top level:
foo.C:7: warning: return type for 'main' changed to integer type

<<<Note: the above warning is only generated with the "-Wall" flag set, but the file compiles fine>>>>
-----------------------------------
xlC -I. -o foo  foo.C
"foo.H", line 15.43: 1540-041: (S) An initializer is not allowed for "class member".
"foo.H", line 16.44: 1540-041: (S) An initializer is not allowed for "class member".
"foo.H", line 11.43: 1540-331: (E) Return value of type "int" is expected.
"foo.C", line 36.1: 1540-017: (W) Return value of type "int" is expected.
ASKER CERTIFIED SOLUTION
Avatar of os012897
os012897

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial