Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Making C better (by borrowing from C++)

Reply
Thread Tools

Making C better (by borrowing from C++)

 
 
Masood
Guest
Posts: n/a
 
      12-23-2007
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
 
Reply With Quote
 
 
 
 
santosh
Guest
Posts: n/a
 
      12-23-2007
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.

 
Reply With Quote
 
 
 
 
Joe Wright
Guest
Posts: n/a
 
      12-23-2007
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 ---
 
Reply With Quote
 
Julienne Walker
Guest
Posts: n/a
 
      12-23-2007
On Dec 23, 10:29 am, Masood <(E-Mail Removed)> 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
 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      12-23-2007
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
http://www.velocityreviews.com/forums/(E-Mail Removed)lid
 
Reply With Quote
 
vippstar@gmail.com
Guest
Posts: n/a
 
      12-23-2007
On Dec 23, 7:00 pm, Julienne Walker <(E-Mail Removed)> wrote:
> On Dec 23, 10:29 am, Masood <(E-Mail Removed)> 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.
 
Reply With Quote
 
Default User
Guest
Posts: n/a
 
      12-23-2007
Masood wrote:

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


*plonk*



Brian

 
Reply With Quote
 
jacob navia
Guest
Posts: n/a
 
      12-23-2007
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
 
Reply With Quote
 
Martin Ambuhl
Guest
Posts: n/a
 
      12-23-2007
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?
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      12-23-2007
Masood <(E-Mail Removed)> 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) <(E-Mail Removed)>
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"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
borrowing Constants Roedy Green Java 22 09-26-2011 02:36 AM
Borrowing a PC? Put Linux on it, via a USB drive Au79 Computer Support 0 08-01-2006 05:53 AM
Making C better (by borrowing from C++) masood.iqbal@lycos.com C Programming 86 02-28-2005 07:04 AM
TIME borrowing in synthesis whizkid VHDL 1 11-02-2004 03:39 PM
Borrowing someone else's XP disc - some questions Gary Glencross Computer Information 4 03-05-2004 03:48 AM



Advertisments