473,569 Members | 2,799 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Making C better (by borrowing from C++)

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

Nov 14 '05 #1
85 3214
ma**********@ly cos.com 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.
Nov 14 '05 #2
On 12 Feb 2005 05:36:00 -0800, ma**********@ly cos.com
<ma**********@l ycos.com> 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
Nov 14 '05 #3
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.c om, 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

Nov 14 '05 #4
ma**********@ly cos.com 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
Nov 14 '05 #5
On 12 Feb 2005 05:36:00 -0800, in comp.lang.c , ma**********@ly cos.com
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 >
Nov 14 '05 #6
On 12 Feb 2005 05:36:00 -0800, in comp.lang.c , ma**********@ly cos.com
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 =----
Nov 14 '05 #7
In article <11************ **********@l41g 2000cwc.googleg roups.com>,
ma**********@ly cos.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?
Nov 14 '05 #8
On Sat, 12 Feb 2005 18:47:44 GMT, CBFalconer
<cb********@yah oo.com> 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
Nov 14 '05 #9
ma**********@ly cos.com 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_Keit h) ks***@mib.org <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.
Nov 14 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

204
4914
by: Masood | last post by:
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,...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8120
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7968
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6283
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5512
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.