Welcome, Guest. Please login or register.

Author Topic: More GNU C++ (ANSI C++ mode) oddness  (Read 2906 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline PiR

  • Full Member
  • ***
  • Join Date: Apr 2003
  • Posts: 148
    • Show all replies
Re: More GNU C++ (ANSI C++ mode) oddness
« on: March 26, 2004, 04:07:24 PM »
Hi Karlos

A specialist in finding GNU bugs, huh? ;-)

I belive you're right and that should be accepted.
However I think I understand the reason why this behaves like so.

In C++ to C metacode conversion for methods you could imagine an additional argument:

void C::Method( ... ); -> void C_Metchod( C *this, ... );

And for inspectors (I was at important talk recently and someone was checking my knowledge and asked me about this and I didn't know the name...) this changes into:

coid C::Inspect( ... ) const; -> void C_Inspect( const C *this, ... );


The reason for this behaviour can be that your method is inlined and then compiler discovers that 'this' is not used, so it removes it completely. If it does not exist it cannot be const.

However, like you, I think this is not correct reaction.

My last conclusion is that your method is actually static function and its best declaration would be:

static int getInstanceCount() { return instances; }

as 'this' is really not needed here.

And I've met this already somewhere that static methods cannot be declared as inspectors - I belive its because of the above reason.

On the other hand this mayby should be accepted also?


Cheers
 

Offline PiR

  • Full Member
  • ***
  • Join Date: Apr 2003
  • Posts: 148
    • Show all replies
Re: More GNU C++ (ANSI C++ mode) oddness
« Reply #1 on: March 26, 2004, 04:39:34 PM »
Ok Karlos

I understand and can share your doubts - inspector that does not change static members.

However I belive that the implementation is as I described - const or not const 'this' pointer. And static members are sort of globals, only their names are mixed with the name of the class... And how could you declare a function that does not modify global values?

The place that I met, rejecting static inspector is HP-UX aCC compiler, quite new one.

Cheers