This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Converting GCC to compilation with C++


Kai Henningsen wrote:

Now explain how, when you do *the exact same thing* with virtual functions or with function pointers, *all* the considerations you listed do not either apply equally to both sides, or else prefer the virtual function side.

Of course a particular instance of the use of dynamic dispatching may present no problems. In this particular case, the criterion would be that all possible execution paths are testable. That's a pretty strenuous criterion, and not very useful because:

  a) many legitimate uses of dispatching do not meet this criterion
  b) many obscure uses do meet this

If you are interested in following this up, there is lots of work
in this area, including some big reports from FAA conferences that
addressed the issue.

Because as far as I can see, they do: if done right, the only difference is syntactical sugar which makes the virtual function version easier to read, _and_ the virtual function version has more chances to catch mistakes at compile time.

This is a bit like saying there is nothing wrong with gotos if you restrict their use to well structured cases like loops. Yes, but you need to be able to formulate the rules for OK uses. For gotos that's easy. It's not so easy for dynamic dispatching.

Comparing arbitrarily complex virtual function use with straightforward function pointer use is comparing diodes with Beowulf clusters.

Well yes, of course, and unrestrained use of function pointers creates chaos (in particular it is trivially the case that function pointers can duplicate all dynamic dispatching capabilities, as is well known from cfront). In practice, in GCC, this chaos does not arise, because function pointers are only used in a very restricted manner.

So, if you move to C++ in the GCC context, you could probably
formulate limited usage for virtual functions that corresponded
only to current usage, and that of course would be just fine.

But are you sure that you want to limit the use of virtual functions
in this way? There are surely other "safe" uses. So the question is
it possible to formulate an appropriate set of restrictions? If so
how can these restrictions be enforced? Is it good enough to rely
on people who review patches? Or are there mechanical limitations.


MfG Kai


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]