Re: why still use C?

From: Jeff Mitchell (quixoticsycophant_at_yahoo.com)
Date: 10/10/03


Date: 9 Oct 2003 15:40:02 -0700

Sidney Cadot <sidney@jigsaw.nl> wrote in message news:<blqeq9$1lc$1@news.tudelft.nl>...
> I can't answer for people in general of course, but as a moderately
> able C programmer with a thorough dislike of C++ I can try to
> explain what my motives are.
<snip>

That was an excellent response, thank you.

For my current work (programming for an embedded device), use of C++
over C is really a matter of notational convenience. I turn off
exceptions and I do not use templates save for one trivial vector
class (hand-written, not STL).

By notational convenience I mean,

(1) I don't need to say self->data, I can just say m_data. It doesn't
    sound like a big deal, but all that s-> clutter really adds up.
    Applications for this device cannot use static data, so every
    piece of data must come from a struct or class.

(2) The ARM CPU doesn't have floating point. It is an enormous
    advantage to define my own fixed-point class with +, -, *, /, etc
    operators.

(3) Virtual functions are used but not common. In this regard I trust
    my C++ compiler. There is very little difference in code size. I
    always know which virtual functions are overridden by which
    subclasses so it's just a "distributed switch statement".

(4) I get a warm, fuzzy feeling using socket.open() verses
    My_Library_Socket_open(socket). You could call this a straw man,
    but I am especially careful about name clashes. The alternatives
    are (a) to be not so careful or (b) to rig function pointers
    inside structs. I don't like either.

(5) 'extern "C"' can be used if you want an application such as
    Mathematica to call into your C++ library. In fact, that's
    exactly what I'm doing.

What is your opinion on using a limited subset of C++, if only for
convenience?

Jeff



Relevant Pages

  • [PATCH 3/4 v2] PCI: support SR-IOV capability
    ... +struct virtfn_slot { ... * The major differences between Virtual Function and PCI device are: ... * transaction to Virtual Functions when they resides on a different ... * bus from Physical Function, so there is no explicit bridge device ...
    (Linux-Kernel)
  • Re: Passing struct of virtual functions
    ... The structure contains virtual functions. ... I'm trying to call this exported win32 DLL function from C#. ... The C struct look something like this ... struct ExportFuncs{ ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Data Structure
    ... >> It's an attempt to fake objects with virtual functions in C. ... You have a pointer to the ... >> vtable as part of each object struct. ... > It's not grossly inefficient. ...
    (comp.lang.c)
  • Re: Data Structure
    ... > It's an attempt to fake objects with virtual functions in C. ... > vtable as part of each object struct. ... It's not grossly inefficient. ...
    (comp.lang.c)
  • Re: Ada 2005?
    ... a struct C cannot contain functions ... But somehow typical for C/C++. ... When has a struct/class a virtual functions table? ... In Ada: allways. ...
    (comp.lang.ada)