bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gnulib] C++ support?


From: Bruno Haible
Subject: Re: [bug-gnulib] C++ support?
Date: Wed, 25 Oct 2006 18:27:47 +0200
User-agent: KMail/1.9.1

Bob Proulx wrote:
> My opinion (which counts for very little here) is that while C++ is
> designed to be as close to C as possible, but no closer, that it is
> still not C.  C++ is not a strict superset of C.  It is close but not
> perfect.

True. Regarding struct and enum type definitions, you have to work out a
set of idioms so that you can write code that is valid in both languages.

> In particular many of the memory handling parts are not 
> compatible.

I didn't find this to be a problem. I can use malloc, xmalloc, free etc. in
C++ as well.

> Silencing bogus C++ errors and warnings also silences 
> valid C errors and warnings.

In C++, you get errors for casts from 'void *' to 'something *'. You then
add casts at these places. Never did these added casts silence valid C
warnings, for me.

> It is possible to craft an environment using defines and inlines to
> make conditional compilation compile C in the C compiler and C++ in
> the C++ compiler to force it compile cleanly with either but this
> means the result is less than optimal in either too.

This sounds weirder than it is. #ifdefs for C++ are only needed in very few
places:
  - in headers, around the 'extern "C"' boilerplate,
  - when you define an 'alignof' macro.

> I have worked on projects where people have tried to be both a C
> project and a C++ project at the same time.  I found that C++
> programmers were always making C mistakes and C programmers were
> always making C++ mistakes.

True. You need to document clearly the idioms for programming in the
intersection between C and C++. And adjust your "make distcheck" target
to verify also the compilation in C++ mode.

> And neither were allowed to program in 
> their language of choice but instead were forced into the least common
> denominator overlay that we created.

Yes, the wealth of features of C++ is tempting. But in the end, you end up
thinking 50% of the time about the weird design of the C++ language features,
rather than on the problem you are programming. You can program in C
subconciously. In C++, you can't.

Bruno




reply via email to

[Prev in Thread] Current Thread [Next in Thread]