[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: a crazy proposal
From:       Jason Mott <jmott () jasonmott ! com>
Date:       2002-12-03 2:01:38
[Download RAW message or body]

I guess I just don't use enough C within C++ to have run into the problems.

Thanks for the info. I stand corrected.

On Monday 02 December 2002 07:58 pm, David Leimbach wrote:
> That's fine...  Except for your insisting that C is a subset of C++.
> Its really not 100% true in all cases by design.
>
> The following will compile in both C and C++.
>
> typedef struct _A {} A;
>
> int main ()
> {
> A a;
> sizeof(a);  //0 in C > 0 in C++.
> }
>
> In C++ objects must have addresses... even empty ones.  I don't know
> what the C standard says about this.
>
> C and C++ are at best siblings... if you don't believe me  Bjarne
> Stroustrup wrote about this recently in the C/C++ Users Journal.  C99
> is even less like C++ than C89 is.  The gap is widening over time and
> it may be important
> to really consider this.
>
> I think this newsgroup post sums up the situation pretty well:
>
>
> And Bjarne has said that "C++ should contain as much of C as possible
> but no more"..  That should also imply something. :)
>
>
> Here are some of his own words on the topic....
>
> http://groups.google.com/
> groups?q=C+is+not+a+subset+of+C%2B%2B&hl=en&lr=&ie=UTF-
> 8&selm=EwH42p.BE0%40research.att.com&rnum=5
>
>
> Dave
>
> On Monday, December 2, 2002, at 06:29 PM, Jason Mott wrote:
> > I wasn't thinking of C++ called from C. I was just thinking of C
> > called from
> > C++. Although I've never fully tested the idea, it is part of the C++
> > specs
> > to be fully C compliant, and I've never run into C code that doesn't
> > compile
> > under C++. That's not to say it doesn't happen though (void pointer
> > example
> > is one case where it happens). :->
> >
> > After I sent the email, I realized that bindings for C to C++ may be
> > the
> > context that was being discussed. But I was thinking the other way
> > around.
> > But what I said remains true of C++ (at least in theory and specs).
> >
> > Thanks for the input.
> >
> > On Monday 02 December 2002 06:54 pm, David Leimbach wrote:
> >>> There shouldn't be a need for C bindings, C++ is backwards compatible
> >>> with C.
> >>> All C code can compile with a C++ compiler, and C libraries can link
> >>> with C++
> >>> code. If you wanted a C++ interface to some C code, all you'd have to
> >>> do is
> >>> encapsulate the code into a class (or encapsulate calls to the C code
> >>> in a
> >>> class).
> >>
> >> This is not true.  C++ contains a subset of C.  Not all legal C code
> >> is
> >> legal C++ code.  C libraries can only link
> >> with C++ code easily if C++ is calling C code... otherwise the name
> >> mangling gets in the way.  The only way to
> >> call C++ code from C is to sacrifice the ability to overload functions
> >> [extern "C" linkage].
> >>
> >> It is still legal to do the following in C though I have trouble
> >> making
> >> sense of it:
> >>
> >> int val;
> >> void * ptr = &val;
> >> ++ptr;  //How far to move the pointer?  am I pointing at
> >> ints/chars/floats???
> >>
> >> C++ should scream loudly about pointer arithmetic on void *..  C just
> >> allows it and its legal.
> >>
> >> That's just one very small difference but believe me... it comes up.
> >> There are others of course.
> >>
> >> Dave
> >>
> >>> --
> >>>
> >>>>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to
> >>>>> unsubscribe <<
> >>>>
> >>>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to
> >>>> unsubscribe <<
> >
> > --
> >
> >> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to
> >> unsubscribe <<

-- 


 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic