Solved

GNU G++ Compiler vs AIX xlC compiler

Posted on 1997-02-04
1
788 Views
Last Modified: 2008-03-04
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.
0
Comment
Question by:kwaldman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 3

Accepted Solution

by:
os012897 earned 150 total points
ID: 1162342
Well, I never worked with xIC so far, but I could tell some tails
about code-sompatibitlty between gcc and cc .... :I!

Different compilers implement the ANSI C++ standard to various
extends, e.g. there are still compilers out there that do not
support templates.

xIC seems to be very strict on return values: Why?

1) Gives the error on the .H file for the virtual function that
   should return an int but does not!
2) Gives you the error in the .C file where you exit, but do not
   return!

For the other two errors
         "An initializer is not allowed for "class member""
there is to say, that you never initialize members in the
class-definition. You do it at the implementation of the class-
constructor like this:

foo :: foo () : FOO_CONST_ONE (-1), FOO_CONST_TWO (-2)

{  implementation of the constructor .....
}

What happens is that you call a kind of "constructor" that sets
the values for the variables, which is why setting the value of
the constant works.

Just keep in mind, that no two C++ compilers are the same and
that there is hardly a program out there that works on different
compilers without applying changes to it!

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
c++ substatte a varabe for a string in a LPCTSTR statment 8 100
C++ question 3 81
Add values of each row in an array 3 80
Outlook 13 100
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question