compile error

S

shishir

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
 
V

Victor Bazarov

shishir said:
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
 
R

Rolf Magnus

shishir said:
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.
 
S

shishir

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.
 
R

Rolf Magnus

shishir said:
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;
}
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.
 
R

Rolf Magnus

Rolf said:
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;
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top