Making C better (by borrowing from C++)

Discussion in 'C Programming' started by Masood, Dec 23, 2007.

  1. Masood

    Masood Guest

    I know that this topic may inflame the "C language Taleban", but is
    there any prospect of some of the neat features of C++ getting
    incorporated in C? No I am not talking out the OO stuff. I am talking
    about the non-OO stuff, that seems to be handled much more elegantly in
    C++, as compared to C. For example new & delete, references, consts,
    declaring variables just before use etc.

    I am asking this question with a vested interest. I would really like
    to use these features in my C programs.

    Masood
     
    Masood, Dec 23, 2007
    #1
    1. Advertising

  2. Masood

    santosh Guest

    Masood wrote:

    > I know that this topic may inflame the "C language Taleban", but is
    > there any prospect of some of the neat features of C++ getting
    > incorporated in C? No I am not talking out the OO stuff. I am
    > talking about the non-OO stuff, that seems to be handled much more
    > elegantly in C++, as compared to C. For example new & delete,
    > references, consts, declaring variables just before use etc.


    Mixed code and declarations and const are already in C. You can use
    malloc and free instead of new and delete and pointers to simulate
    references.

    > I am asking this question with a vested interest. I would really like
    > to use these features in my C programs.


    Try lcc-win from jacob navia. It's just for folks like you. Don't have
    too much hope of seeing them in C.
     
    santosh, Dec 23, 2007
    #2
    1. Advertising

  3. Masood

    Joe Wright Guest

    Masood wrote:
    > I know that this topic may inflame the "C language Taleban", but is
    > there any prospect of some of the neat features of C++ getting
    > incorporated in C? No I am not talking out the OO stuff. I am talking
    > about the non-OO stuff, that seems to be handled much more elegantly in
    > C++, as compared to C. For example new & delete, references, consts,
    > declaring variables just before use etc.
    >
    > I am asking this question with a vested interest. I would really like
    > to use these features in my C programs.
    >
    > Masood


    As you seem willing to modify your C programs to incorporate these
    features, why not change the source file extension from .c to .cc and
    feed it to your favorite C++ compiler?

    --
    Joe Wright
    "Everything should be made as simple as possible, but not simpler."
    --- Albert Einstein ---
     
    Joe Wright, Dec 23, 2007
    #3
  4. On Dec 23, 10:29 am, Masood <> wrote:
    > I know that this topic may inflame the "C language Taleban", but is
    > there any prospect of some of the neat features of C++ getting
    > incorporated in C? No I am not talking out the OO stuff. I am talking
    > about the non-OO stuff, that seems to be handled much more elegantly in
    > C++, as compared to C. For example new & delete


    There's no need for new and delete aside from a minor syntactic
    convenience as the big difference between malloc/delete and friends is
    that new and delete properly handle constructors and destructors.
    Adding new and delete to C would do little more than complicate the
    language without buying you anything.

    > references


    References exist in C++ mainly to supplement operator overloading. I
    personally wouldn't mind references or operator overloading in C, but
    this newsgroup isn't the place to discuss improvements to the
    language, it's the place to discuss the language as defined by one of
    the standards.

    > consts


    C supports const. Presumably you mean a stronger const that can be
    used as an array size:

    int main ( void )
    {
    const int foo = 10;
    int bar[foo];

    return 0;
    }

    And you want this to avoid manifest constants with the preprocessor.

    > declaring variables just before use etc.


    C99 already supports this. Though I'm not convinced that it's a
    desirable feature in C. In fact, except in a few well defined cases,
    I'm leaning toward recommending that despite the fact you can now mix
    declarations and statements, it's a better practice to continue
    placing all declarations at the top of a block.

    > I am asking this question with a vested interest. I would really like
    > to use these features in my C programs.


    I don't know of any proposals that *weren't* born of a vested
    interest. ;-) Nobody stands up and says "I'd never use this or care
    about it, but how about we add <xxx> feature? That'd be cool."


    -Jul
     
    Julienne Walker, Dec 23, 2007
    #4
  5. Masood

    Eric Sosman Guest

    Masood wrote:
    > I know that this topic may inflame the "C language Taleban", but is
    > there any prospect of some of the neat features of C++ getting
    > incorporated in C? No I am not talking out the OO stuff. I am talking
    > about the non-OO stuff, that seems to be handled much more elegantly in
    > C++, as compared to C. For example new & delete, references, consts,
    > declaring variables just before use etc.
    >
    > I am asking this question with a vested interest. I would really like
    > to use these features in my C programs.


    Only two of these seem to be of much use in C. Declarations
    mixed with statements are already allowed by the C99 Standard, so
    your wish is granted. The semantics of `const' (meaning "read-
    only" rather than "compile-time constant") seem unlikely to change
    at this point, so you probably don't get that one -- but plain C
    offers alternatives that may suffice for many situations.

    I find it hard to imagine how new and delete can be of much
    benefit without constructors and destructors to go along with
    them. All they could do is reserve and release memory, and C
    already has mechanisms (plural) to do that. If you want to drag
    in constructors and destructors to make new and delete useful,
    I think you're bringing in too much of "the OO stuff" that you
    intended to avoid.

    References -- well, I'm not a C++ programmer and do not claim
    to understand references fully. When I want a function to change
    something the caller supplies to it, I use a pointer and all is
    well. What do you want to accomplish that pointers can't handle?

    Finally, you might want to avoid inflammatory epithets if
    you want serious consideration of your ideas and proposals. True,
    a few contributors to this forum habitually lard their arguments
    with explicit assumptions that all opponents are fools and morons,
    but you might take a lesson from the notable lack of success such
    arguments have met. Make your arguments on their merits, because
    they'll be rejected out of hand if you make them on their demerits.

    --
    Eric Sosman
    lid
     
    Eric Sosman, Dec 23, 2007
    #5
  6. Masood

    Guest

    On Dec 23, 7:00 pm, Julienne Walker <> wrote:
    > On Dec 23, 10:29 am, Masood <> wrote:
    > > consts

    >
    > C supports const. Presumably you mean a stronger const that can be
    > used as an array size:
    >
    > int main ( void )
    > {
    > const int foo = 10;
    > int bar[foo];
    >
    > return 0;
    >
    > }


    foo needs not to be const.
     
    , Dec 23, 2007
    #6
  7. Masood

    Default User Guest

    Masood wrote:

    > I know that this topic may inflame the "C language Taleban"


    *plonk*



    Brian
     
    Default User, Dec 23, 2007
    #7
  8. Masood

    jacob navia Guest

    santosh wrote:
    > Masood wrote:
    >
    >> I know that this topic may inflame the "C language Taleban", but is
    >> there any prospect of some of the neat features of C++ getting
    >> incorporated in C? No I am not talking out the OO stuff. I am
    >> talking about the non-OO stuff, that seems to be handled much more
    >> elegantly in C++, as compared to C. For example new & delete,
    >> references, consts, declaring variables just before use etc.

    >
    > Mixed code and declarations and const are already in C. You can use
    > malloc and free instead of new and delete and pointers to simulate
    > references.
    >
    >> I am asking this question with a vested interest. I would really like
    >> to use these features in my C programs.

    >
    > Try lcc-win from jacob navia. It's just for folks like you. Don't have
    > too much hope of seeing them in C.
    >


    The lcc-win compiler system introduced several features from C++
    as C extensions:

    o operator overloading
    o generic functions
    o default arguments
    o Garbage collector
    o references

    You can download the lcc-win compiler system from the URL below

    --
    jacob navia
    jacob at jacob point remcomp point fr
    logiciels/informatique
    http://www.cs.virginia.edu/~lcc-win32
     
    jacob navia, Dec 23, 2007
    #8
  9. Masood wrote:
    > I know that this topic may inflame the "C language Taleban", but is
    > there any prospect of some of the neat features of C++ getting
    > incorporated in C? No I am not talking out the OO stuff. I am talking
    > about the non-OO stuff, that seems to be handled much more elegantly in
    > C++, as compared to C. For example new & delete,


    If you actually have used new and delete, you know that they are more
    limited than the standard C functions.

    > references,


    Completely unneeded syntactical sugar, designed to help people who write
    bad code write even sloppier code.

    > consts,


    C has const; C has constants (and enums). There is no need for C++
    semantics.

    > declaring variables just before use etc.


    C has declaring variables just before use. This was added so that
    people who write bad code can write even sloppier code. Even without
    it, as in the pre-C99 standard, introducing a block will generally
    provide all the legitimate need you might have for such a thing.

    >
    > I am asking this question with a vested interest. I would really like
    > to use these features in my C programs.


    Why? What possible advantage is there?
     
    Martin Ambuhl, Dec 23, 2007
    #9
  10. Masood <> writes:
    > I know that this topic may inflame the "C language Taleban", but

    [SNIP]

    Until and unless you apologize for the above insult, I will not
    discuss this or anything else with you.

    --
    Keith Thompson (The_Other_Keith) <>
    Looking for software development work in the San Diego area.
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Dec 23, 2007
    #10
  11. On 23 Dec 2007 at 19:10, Keith Thompson wrote:
    > Masood <> writes:
    >> I know that this topic may inflame the "C language Taleban", but

    > [SNIP]
    >
    > Until and unless you apologize for the above insult, I will not
    > discuss this or anything else with you.


    Ha ha, that's a laugh. Heath Field's most faithful lieutentant wouldn't
    ever discuss anything as off-topic as possible improvements to C with
    you, whether or not you insult him.

    (Interesting to note that HeathField's supporters know who's meant by
    the "C Taleban")
     
    Antoninus Twink, Dec 23, 2007
    #11
  12. Masood

    Tim Smith Guest

    In article <fklut4$mvt$>, Masood <>
    wrote:
    > I know that this topic may inflame the "C language Taleban", but is


    If you are going to insult people, fuckhead, do it right. It is Taliban.


    --
    --Tim Smith
     
    Tim Smith, Dec 23, 2007
    #12
  13. Tim Smith <> writes:
    > In article <fklut4$mvt$>, Masood <>
    > wrote:
    >> I know that this topic may inflame the "C language Taleban", but is

    >
    > If you are going to insult people, [deleted], do it right. It is Taliban.


    <OT>Both spellings are correct.</OT>

    --
    Keith Thompson (The_Other_Keith) <>
    Looking for software development work in the San Diego area.
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Dec 23, 2007
    #13
  14. Masood

    CBFalconer Guest

    Masood wrote:
    >
    > I know that this topic may inflame the "C language Taleban", but
    > is there any prospect of some of the neat features of C++ getting
    > incorporated in C? No I am not talking out the OO stuff. I am
    > talking about the non-OO stuff, that seems to be handled much more
    > elegantly in C++, as compared to C. For example new & delete,
    > references, consts, declaring variables just before use etc.
    >
    > I am asking this question with a vested interest. I would really
    > like to use these features in my C programs.


    I suggest you just use C++ (and the appropriate newsgroup) and
    write the appropriate programs. The languages are different, and
    attempting to combine them (as they stand) will just lead to
    confusion and errors.

    You don't have to use GUI, object orientation, etc. in either
    language.

    --
    Merry Christmas, Happy Hanukah, Happy New Year
    Joyeux Noel, Bonne Annee.
    Chuck F (cbfalconer at maineline dot net)
    <http://cbfalconer.home.att.net>



    --
    Posted via a free Usenet account from http://www.teranews.com
     
    CBFalconer, Dec 24, 2007
    #14
  15. Masood

    Chris Hills Guest

    In article <>, Keith Thompson
    <> writes
    >Masood <> writes:
    >> I know that this topic may inflame the "C language Taleban", but

    >[SNIP]
    >
    >Until and unless you apologize for the above insult, I will not
    >discuss this or anything else with you.


    Then don't... Was it aimed at you personally?

    In any event you now see how c.l.c is seen by many people. The "C
    language Taliban" A group of "religious" nutters.

    This is why I have been saying c.l.c needs to relax a but from some of
    the pedantry being enforced by a small but vocal group

    --
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
    \/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
    /\/\/ www.phaedsys.org \/\/\
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
     
    Chris Hills, Dec 24, 2007
    #15
  16. Chris Hills said:

    <snip>

    > In any event you now see how c.l.c is seen by many people. The "C
    > language Taliban" A group of "religious" nutters.


    Er, so? Lots of people view with considerable suspicion anyone having an
    above-room-temperature IQ. Big deal.

    > This is why I have been saying c.l.c needs to relax a but from some of
    > the pedantry being enforced by a small but vocal group


    Firstly, nobody enforces anything here; everyone is free to post as much
    off-topic inaccurate junk as they can find the time to compose.

    Secondly, by what power or authority does this supposed group enforce
    anything? (If the answer is "none", then you contradict yourself.)

    Thirdly, the size of the group of people who post topical, (mostly)
    correct, and helpful information here considerably exceeds the size of the
    group that prefers to spend its time carping and sneering at those who
    actually offer help.

    Fourthly, regarding pedantry: it appears that you wish the level of
    accuracy of answers posted in comp.lang.c to be lowered. Obviously, what
    others post is their affair, but from me the answer is "no". I will not
    deliberately be wrong in a vain bid to be popular. That would be very
    silly indeed.

    --
    Richard Heathfield <http://www.cpax.org.uk>
    Email: -http://www. +rjh@
    Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
    "Usenet is a strange place" - dmr 29 July 1999
     
    Richard Heathfield, Dec 24, 2007
    #16
  17. Masood

    Richard Guest

    Keith Thompson <> writes:

    > Masood <> writes:
    >> I know that this topic may inflame the "C language Taleban", but

    > [SNIP]
    >
    > Until and unless you apologize for the above insult, I will not
    > discuss this or anything else with you.


    Then don't. You wouldn't have done so anyway other than to say "OT, not
    discussed, blah, blah, blah".

    In fact, I think the OP meant you and RH when he mentioned the C
    Taleban. Not a bad reference. Closed minded, not open to change, think
    they are in charge "for the best" of everyone else.
     
    Richard, Dec 24, 2007
    #17
  18. Chris Hills <> writes:
    > In article <>, Keith Thompson
    > <> writes
    >>Masood <> writes:
    >>> I know that this topic may inflame the "C language Taleban", but

    >>[SNIP]
    >>
    >>Until and unless you apologize for the above insult, I will not
    >>discuss this or anything else with you.

    >
    > Then don't... Was it aimed at you personally?


    Such insults are typically aimed at "the regulars", of which I am one.
    Yes, it very likely was aimed at me and a few others. (If it wasn't,
    Masood is free to say so.)

    In any case, it doesn't really matter at whom it was aimed. Such
    gratuitous preemptive attacks are inappropriate here. Don't you
    agree?

    > In any event you now see how c.l.c is seen by many people. The "C
    > language Taliban" A group of "religious" nutters.


    A small number of trolls claim to see it that way. I hope you don't.
    You generally seem more sane than that.

    > This is why I have been saying c.l.c needs to relax a but from some of
    > the pedantry being enforced by a small but vocal group


    We've had this discussion. Richard Heathfield posted an informal
    survey asking whether the topicality guidelines for this group should
    be loosened. The majority of responders said they shouldn't.

    --
    Keith Thompson (The_Other_Keith) <>
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Dec 24, 2007
    #18
  19. Masood

    jacob navia Guest

    Richard Heathfield wrote:
    > Chris Hills said:
    >
    > <snip>
    >
    >> In any event you now see how c.l.c is seen by many people. The "C
    >> language Taliban" A group of "religious" nutters.

    >
    > Er, so? Lots of people view with considerable suspicion anyone having an
    > above-room-temperature IQ. Big deal.
    >
    >> This is why I have been saying c.l.c needs to relax a but from some of
    >> the pedantry being enforced by a small but vocal group

    >
    > Firstly, nobody enforces anything here; everyone is free to post as much
    > off-topic inaccurate junk as they can find the time to compose.
    >


    You are the living proof of that

    > Secondly, by what power or authority does this supposed group enforce
    > anything? (If the answer is "none", then you contradict yourself.)
    >


    By insulting througha nonymous posts everyone that doesn't agree with
    their parochial views

    YOU rezcommend libcurl in this thread but when I
    recommend lcc-win I am a "notorious spammer"


    --
    jacob navia
    jacob at jacob point remcomp point fr
    logiciels/informatique
    http://www.cs.virginia.edu/~lcc-win32
     
    jacob navia, Dec 24, 2007
    #19
  20. jacob navia said:

    > Richard Heathfield wrote:
    >> Chris Hills said:
    >>

    <snip>

    >>> This is why I have been saying c.l.c needs to relax a but from some of
    >>> the pedantry being enforced by a small but vocal group

    >>
    >> Firstly, nobody enforces anything here; everyone is free to post as much
    >> off-topic inaccurate junk as they can find the time to compose.

    >
    > You are the living proof of that


    I see no justification for that claim.

    >> Secondly, by what power or authority does this supposed group enforce
    >> anything? (If the answer is "none", then you contradict yourself.)

    >
    > By insulting througha nonymous posts everyone that doesn't agree with
    > their parochial views


    Anonymous posting confers neither power nor authority. Nor does it carry
    respect. Those who hide behind anonymity to make personal attacks are
    beneath contempt. If you are suggesting that such cowards are, or are
    under the control of, regular contributors to this group, then you really
    don't understand the people you attack. I can't see any of them stooping
    so low.

    > YOU rezcommend libcurl in this thread but when I
    > recommend lcc-win I am a "notorious spammer"


    Right. I didn't write libcurl, nor am I responsible for maintaining it, nor
    do I stand to make any money off it. I have no financial interest
    whatsoever in its success. Nor am I associated with any who do. You,
    however, have a vested financial interest in lcc-win's success. So your
    promotion of it can hardly claim to be a disinterested and independent
    recommendation.

    --
    Richard Heathfield <http://www.cpax.org.uk>
    Email: -http://www. +rjh@
    Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
    "Usenet is a strange place" - dmr 29 July 1999
     
    Richard Heathfield, Dec 24, 2007
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. whizkid

    TIME borrowing in synthesis

    whizkid, Nov 2, 2004, in forum: VHDL
    Replies:
    1
    Views:
    6,500
    Tom Verbeure
    Nov 2, 2004
  2. Replies:
    86
    Views:
    1,470
    Dave Thompson
    Feb 28, 2005
  3. Peter Bencsik
    Replies:
    2
    Views:
    856
  4. Roedy Green

    borrowing Constants

    Roedy Green, Sep 24, 2011, in forum: Java
    Replies:
    22
    Views:
    616
    Arne Vajhøj
    Sep 26, 2011
  5. Novice

    "Borrowing" code

    Novice, Feb 16, 2012, in forum: Java
    Replies:
    60
    Views:
    1,123
    Novice
    Feb 20, 2012
Loading...

Share This Page