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.iqbal@lycos.com
Guest
Posts: n/a
 
      02-12-2005
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
 
 
 
 
infobahn
Guest
Posts: n/a
 
      02-12-2005
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,


Pointless without adding constructors and destructors too, which
might be further than the C community wants to go.

> references,


An excellent way to confuse people still further wrt pointers.

> consts,


Got them.

> declaring variables just before use etc.


Got them in C99.
 
Reply With Quote
 
 
 
 
Chris Croughton
Guest
Posts: n/a
 
      02-12-2005
On 12 Feb 2005 05:36:00 -0800,
<> 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.


Note that quite a few features have already made it back -- void,
declaring variables in the middle of code, single-line comments for
instance.

There is no point to new and delete without constructors and
destructors, and to have those you'd need to introduce classes (and then
you'd have "C with classes", which was how C++ started out.

References are nice in some ways, but are really just syntactic sugar
round pointers, and can be even more confusing (especially when it isn't
obvious that a parameter may change).

Proper named and typed constants would indeed be useful, C's version of
const is a compiler convenience, and I can see those making it into C at
some point, but most of the other features depend on classes.

I can think of other things I'd like more. A typeof operator, for
example, and to have known-width arithmetic types build into the
language instead of via a header file (which isn't guaranteed to even
provide them). I'd really like a portable way of having enum values as
strings so that I could use strtoenum() for input and a printf
descriptor to output an enum as its named values. I'd like those in C++
as well...

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


Why not use C++ instead, if that's what you like? That's what I do, I
use C++ for things where I want high-level features and I use C for
portability (adding C++ features to C won't make them portable, we're
over 5 years after the last C standard came out and I still can't safely
assume that any of the features introduced are portable (there seems to
be possibly one compiler and library which is fully C99 compliant) and
some systems don't even fully implement the standard from 10 years
before that).

Chris C
 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      02-12-2005
Chris Croughton wrote:
>

.... snip ...
>
> References are nice in some ways, but are really just syntactic
> sugar round pointers, and can be even more confusing (especially
> when it isn't obvious that a parameter may change).


I used to miss them sorely, but eventually got used to the idea
that the caller can tell when it is exposing its internal data to
outside influence without examining the header of the called
function. Of course the cost is that pointers are not under
control, and that proper verification is impossible to all
practical purposes.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson

 
Reply With Quote
 
Mark McIntyre
Guest
Posts: n/a
 
      02-12-2005
On 12 Feb 2005 05:36:00 -0800, in comp.lang.c ,
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?


Some C++ features made it into C99. Others don't make sense in C, such as
new, delete, reference variables and so forth. For your info consts have
been in C for decades, and declare-before-use is in C99.

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


Then use C++

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>
 
Reply With Quote
 
jacob navia
Guest
Posts: n/a
 
      02-12-2005
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
>


The lcc-win32 compiler adds some features of C++ like:

o operator overloading
o default arguments to functions
o references

Declaring variables just vefore use is part of the
C99 standard

http://www.cs.virginia.edu/~lcc-win32
 
Reply With Quote
 
Mark McIntyre
Guest
Posts: n/a
 
      02-12-2005
On 12 Feb 2005 05:36:00 -0800, in comp.lang.c ,
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?


Some C++ features made it into C99. Others don't make sense in C, such as
new, delete, reference variables and so forth. For your info consts have
been in C for decades, and declare-before-use is in C99.

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


Then use C++

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
 
Reply With Quote
 
Christian Bau
Guest
Posts: n/a
 
      02-12-2005
In article < .com>,
wrote:

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


Not very clever starting with an insult like that, if you want to be
taken serious?
 
Reply With Quote
 
Chris Croughton
Guest
Posts: n/a
 
      02-12-2005
On Sat, 12 Feb 2005 18:47:44 GMT, CBFalconer
<> wrote:

> Chris Croughton wrote:
>>

> ... snip ...
>>
>> References are nice in some ways, but are really just syntactic
>> sugar round pointers, and can be even more confusing (especially
>> when it isn't obvious that a parameter may change).

>
> I used to miss them sorely, but eventually got used to the idea
> that the caller can tell when it is exposing its internal data to
> outside influence without examining the header of the called
> function. Of course the cost is that pointers are not under
> control, and that proper verification is impossible to all
> practical purposes.


When I'm writing C++ I use reference parameters, because I like the
cleanness of the call. However I've been bitten by them several times,
so it's a kind of "love-hate" relationship, I can see good reasons both
for using them and for avoiding them. The thing I do like and miss from
C++ (which C99 has now but none of the compilers for which I have to
write portable C code supports) is declaring 'local' loop variables:

for (int i = 0; i < n; ++i)
...

I'm always forgetting that C89 doesn't have that...

Chris C
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      02-12-2005
writes:
> 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.


As others have pointed out, some of these things are already in C99.
And I believe that prototypes were first introduced in (pre-standard)
C++ and added to C with the 1989 ANSI standard. I don't think there's
any great resistance to the idea of adding some C++ features to C *if*
they fit into the C language.

On the other hand, if you want C++ features that C doesn't have, the
easiest way to get them is to use C++.

Incidentally, calling people "Taleban" is a really bad way to
influence them.

--
Keith Thompson (The_Other_Keith) kst- <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
 
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
Making C better (by borrowing from C++) Masood C Programming 247 01-14-2008 05:42 AM
Borrowing a PC? Put Linux on it, via a USB drive Au79 Computer Support 0 08-01-2006 05:53 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