Making C better (by borrowing from C++)

M

Masood

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
 
S

santosh

Masood said:
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.
 
J

Joe Wright

Masood said:
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?
 
J

Julienne Walker

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.

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
 
E

Eric Sosman

Masood said:
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.
 
J

jacob navia

santosh said:
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.


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
 
M

Martin Ambuhl

Masood said:
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.

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?
 
K

Keith Thompson

Masood said:
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.
 
A

Antoninus Twink

Masood said:
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")
 
C

CBFalconer

Masood said:
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.
 
C

Chris Hills

Keith Thompson said:
Masood said:
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
 
R

Richard Heathfield

Chris Hills said:

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.
 
R

Richard

Keith Thompson said:
Masood said:
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.
 
K

Keith Thompson

Chris Hills said:
Keith Thompson said:
Masood said:
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.
 
J

jacob navia

Richard said:
Chris Hills said:



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


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"
 
R

Richard Heathfield

jacob navia said:
You are the living proof of that

I see no justification for that claim.
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top