13

I am very interrogative and perplexed by this commit on android's dalvik platform pushed a year ago.

File extensions were changed to C++ extensions in order to "move the interpreter into C++" - use the compiler's C++ front-end.

What could be the benefits of this change ? Dalvik Platform is a 100% C & asm project and not any C++ feature is used.

Julio Guerra
  • 5,523
  • 9
  • 51
  • 75

1 Answers1

3

I can only speculate, but considering how the Android system has grown in complexity, the scoping features of C++ (classes and namespaces) might make the code base more manageable.

EDIT

Even if the project doesn't currently make use of any C++ features, they may simply be planning ahead.

Apart from some minor differences (namely some parameter conventions most people avoid anyway), C source code compiles as C++ without modification. That being said, in some areas C++ syntax is stricter than C (C allows you to assign a void pointer to another pointer type without a cast; in C++, this is an error), and enforcing this strictness avoids problems down the road. *

*) (That's an overly simplistic view, see comment)

One further reason for the change may be that because most modern development favors C++ over C, a richer set of tools is available.

Speculating again, but at the birth of Android C may have been the only viable option for embedded device development, and now that restriction is no longer an issue.

Tony the Pony
  • 40,327
  • 71
  • 187
  • 281
  • That was my first reaction, but I did not find any C++ features used in the code. – Julio Guerra May 22 '12 at 09:52
  • 3
    No, C and C++ are basically only interface compatible and not compile compatible. There are many, many small pitfalls, starting from scopes for naming types, to different concept of compile time constants, and stuff like that. – Jens Gustedt May 22 '12 at 10:10
  • @JensGustedt Good point! As long as one follows the stricter syntax requirements of C++, can one ever treat C as a subset of C++? – Tony the Pony May 22 '12 at 10:20
  • 1
    @Tony the Pony: there is a common subset of the two languages, but writing in it basically requires knowing both of them thoroughly, which is harder than just picking one and sticking to it. I'd say save that for header files intended for use from both languages. – Steve Jessop May 22 '12 at 10:28