compile error

Discussion in 'C++' started by shishir, Aug 26, 2004.

  1. shishir

    shishir Guest

    hi
    the following may be offtopic.
    gcc 3.3.3 compiler throws error like

    .....: error: invalid in-class
    initialization of static data member of non-integral type `const
    char[]'

    ...... error: looser throw specifier for virtual void X::y()
    etc

    for the same source gcc 2.95.2 doesn't throw any error. What could be
    the reason ?
    1 more thing...-fno-rtti doesn't have any affect on gcc 3.3.3. In both
    the cases -frtti and -fno-rtti, code generated are same.
    did i miss any patch or what is the recent gcc version which works ?

    Thanks
     
    shishir, Aug 26, 2004
    #1
    1. Advertising

  2. shishir wrote:
    > the following may be offtopic.
    > gcc 3.3.3 compiler throws error like
    >
    > ....: error: invalid in-class
    > initialization of static data member of non-integral type `const
    > char[]'
    >
    > ..... error: looser throw specifier for virtual void X::y()
    > etc
    >
    > for the same source gcc 2.95.2 doesn't throw any error. What could be
    > the reason ?


    I know of one reason: 3.3.3 is more Standard-compliant than 2.95.2.

    > 1 more thing...-fno-rtti doesn't have any affect on gcc 3.3.3. In both
    > the cases -frtti and -fno-rtti, code generated are same.
    > did i miss any patch or what is the recent gcc version which works ?


    Ask in gnu.gcc.help. Adding or not adding RTTI has no effect if your
    code doesn't use RTTI (typeid operator and so on)

    Victor
     
    Victor Bazarov, Aug 26, 2004
    #2
    1. Advertising

  3. shishir

    Rolf Magnus Guest

    shishir wrote:

    > hi
    > the following may be offtopic.
    > gcc 3.3.3 compiler throws error like
    >
    > ....: error: invalid in-class
    > initialization of static data member of non-integral type `const
    > char[]'
    >
    > ..... error: looser throw specifier for virtual void X::y()
    > etc
    >
    > for the same source gcc 2.95.2 doesn't throw any error. What could be
    > the reason ?


    Maybe just because you did the things it's complaining about. Newer
    versions of gcc are much more standard compliant than older ones,
    resulting in more errors if your code is invalid.

    > 1 more thing...-fno-rtti doesn't have any affect on gcc 3.3.3. In both
    > the cases -frtti and -fno-rtti, code generated are same.


    Are you actually using any rtti in your code?

    > did i miss any patch or what is the recent gcc version which works ?


    They should all work well.
     
    Rolf Magnus, Aug 26, 2004
    #3
  4. shishir

    shishir Guest

    > Are you actually using any rtti in your code?
    int main()
    {
    try
    {
    throw new int()
    }
    catch (...)
    {
    printf("\nCaught");
    }
    }

    the above piece of code produces the same object code with -frrti and
    -fno-rtti option.

    > They should all work well.

    Also, gcc fails to link c++ object codes, it is the g++ which is able
    to link.
     
    shishir, Aug 27, 2004
    #4
  5. shishir

    Rolf Magnus Guest

    shishir wrote:

    >> Are you actually using any rtti in your code?

    > int main()
    > {
    > try
    > {
    > throw new int()
    > }
    > catch (...)
    > {
    > printf("\nCaught");
    > }
    > }
    >
    > the above piece of code produces the same object code with -frrti and
    > -fno-rtti option.


    That's because it doesn't use RTTI. You seem to be confusing exceptions
    with RTTI.
    Try this instead:

    #include <iostream>

    struct A { virtual ~A() {} };
    struct B: public A {};

    int main()
    {
    A* a = new B();
    std::cout << typeid(a).name() << std::endl;
    delete a;
    }

    >> They should all work well.

    > Also, gcc fails to link c++ object codes, it is the g++ which is able
    > to link.


    Yes. That's intended. gcc won't link in the C++ standard library.
     
    Rolf Magnus, Aug 27, 2004
    #5
  6. shishir

    Rolf Magnus Guest

    Rolf Magnus wrote:

    > shishir wrote:
    >
    >>> Are you actually using any rtti in your code?

    >> int main()
    >> {
    >> try
    >> {
    >> throw new int()
    >> }
    >> catch (...)
    >> {
    >> printf("\nCaught");
    >> }
    >> }
    >>
    >> the above piece of code produces the same object code with -frrti and
    >> -fno-rtti option.

    >
    > That's because it doesn't use RTTI. You seem to be confusing
    > exceptions with RTTI.
    > Try this instead:
    >
    > #include <iostream>
    >
    > struct A { virtual ~A() {} };
    > struct B: public A {};
    >
    > int main()
    > {
    > A* a = new B();
    > std::cout << typeid(a).name() << std::endl;


    Oops. Of course, it would have to be:

    std::cout << typeid(*a).name() << std::endl;

    > delete a;
    > }
    >
    >>> They should all work well.

    >> Also, gcc fails to link c++ object codes, it is the g++ which is able
    >> to link.

    >
    > Yes. That's intended. gcc won't link in the C++ standard library.
     
    Rolf Magnus, Aug 27, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nagaraj
    Replies:
    1
    Views:
    917
    Lionel B
    Mar 1, 2007
  2. timjowers
    Replies:
    7
    Views:
    4,418
    heyjude
    Feb 2, 2011
  3. Replies:
    1
    Views:
    470
    Cowboy \(Gregory A. Beamer\)
    Apr 11, 2008
  4. Carter
    Replies:
    2
    Views:
    528
    Carter
    Mar 4, 2009
  5. fAnSKyer
    Replies:
    2
    Views:
    567
    Alf P. Steinbach
    Jun 7, 2009
Loading...

Share This Page