473,396 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Any quick reference for the difference between C and C++

Hi,

I have been using C++ a lot and I've almost forgot what syntax is
support by C and what syntax is support by C++? My feeling is that C++
gives programmer much flexibility. And the code is more localized in
C++ than C, which mean changes won't propogate far away in C++ code. By
reusing through inherence and overloading, a lot of code can be saved.

But I have to use C for some reason. Is there any programming paradigm
in C, which can give me as much advantage that C++ as possilbe? Is
there any quick reference which can tell me what C++ syntax is
forbidden in C?

Best wishes,
Peng

Nov 14 '05 #1
14 1627
Hi, i am new member here.

I am afraid of c++, so i just chose c. my recommendation is
http://www.faqs.org/docs/artu/

--
PS: my 1st post on c.l.c, yay! ;)

Nov 14 '05 #2
"Pe*******@gmail.com" wrote:

Hi,

I have been using C++ a lot and I've almost forgot what syntax is
support by C and what syntax is support by C++? My feeling is that C++
gives programmer much flexibility.
I don't know who said it but I agree with this statement:

C offers you enough rope to hang yourself. C++ offers a
fully equipped firing squad, a last cigarette and a blindfold.
And the code is more localized in
C++ than C, which mean changes won't propogate far away in C++ code.


I think your jugdements on C here are based on the C code
you have worked on and have little to do with C in general.

Erik
--
+-----------------------------------------------------------+
Erik de Castro Lopo no****@mega-nerd.com (Yes it's valid)
+-----------------------------------------------------------+
"Python addresses true pseudocode's two major failings: that it
isn't standardized, and it isn't executable."
- Grant R. Griffin in comp.dsp
Nov 14 '05 #3
Hmm,both C and C++ are very successful.Choosing which of them depends
on what you want to do.If you like to do some low-level programming
like me,C is a better choice.And if you like OOP,C++ can be a better
choice.Er,Java is also one of the C-family languages,right?

Nov 14 '05 #4
<Pe*******@gmail.com> wrote

I have been using C++ a lot and I've almost forgot what syntax is
support by C and what syntax is support by C++?
new, delete, operator, class, public, private, protected, template,
namespace are C++ keywords.
inline is not C89, but is widely supported. Ditto "//" comments.
references eg void cursor(int &x, int &y) are C++ only.

That's pretty much all you need to know, though run code through a C
compiler if you want to use the common subset.
My feeling is that C++ gives programmer much flexibility.
Yes. There are usually more good approaches to a problem in C++ than in C.
And the code is more localized in C++ than C, which mean changes won't
propogate far away in C++ code. By reusing through inherence and
overloading, a lot of code can be saved.
This is very arguable. By declaring a C file with a few public functions and
a lot of static functions you can have something that is actually more
encapsulated than a C++ class.
But I have to use C for some reason. Is there any programming paradigm
in C, which can give me as much advantage that C++ as possilbe? Is
there any quick reference which can tell me what C++ syntax is
forbidden in C?

There is a difference between programming with objects, and object-oriented
programming. C programs using objects, for instance a structure that is
declared in a file, and with functions that operate on it, are common and
work well. It is possible to do object-orientation in C, where the objects
have relationships with each other, so all our "line" objects have a common
"getlength() method. However it normally a mistake because the syntax of
setting up function pointers and nested structures and the like gets so
horrible. That's why C++ was invented

Sometimes people use "object-oriented" as a synonym for "well-designed".
Procedural programs can be just as maintainable and well-structured as
object-oriented ones.
Nov 14 '05 #5
Could you introduce me any information on good C programming style?
Thanks!

Peng

Nov 14 '05 #6
"Pe*******@gmail.com" wrote:

Could you introduce me any information on good C programming style?


Surely. Just go to my site, download section (URL in organization
header), and look at my C code. It is perfection personified :-)

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

Nov 14 '05 #7
Pe*******@gmail.com wrote:
Could you introduce me any information on good C programming style?
Thanks!


Easy-Peasy:
1. Avoid UB.
2. ???
3. PROFIT!!!

Although a required reading is on the table to get #1 right.
Nov 14 '05 #8
On 4 Jun 2005 21:25:40 -0700, "Pe*******@gmail.com"
<Pe*******@gmail.com> wrote:
Is there any quick reference which can tell me what C++ syntax is
forbidden in C?


Well, here's a link :

http://david.tribble.com/text/cdiffs.htm#C++-vs-C

Nov 14 '05 #9
Could you explain these items one by one? Thank!

Nov 14 '05 #10
I don't see your site url. Could you show it to me? Thanks!

Nov 14 '05 #11
"Pe*******@gmail.com" <Pe*******@gmail.com> writes:
Could you explain these items one by one? Thank!


What items? Don't assume that your readers have access to the article
to which you're replying. The Google Groups interface makes it far
too easy to post followups that do not quote the previous article, but
it is possible (but harder than it should be) to do it properly.

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.

As it happens, I was able to read the parent article. It was a joke.
If you don't understand the reference, just ignore it.

--
Keith Thompson (The_Other_Keith) 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 #12
"Pe*******@gmail.com" <Pe*******@gmail.com> writes:
I don't see your site url. Could you show it to me? Thanks!


I'm sure he'll be happy to do so *if* you post a followup to his
article that quotes it properly. As it is, there's no easy way to
tell what you're talking about, and the person you're addressing
probably won't bother.

To find out how to do this, see my other followup in this thread.

--
Keith Thompson (The_Other_Keith) 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 #13
> new, delete, operator, class, public, private, protected, template,
namespace are C++ keywords.
inline is not C89, but is widely supported. Ditto "//" comments.
references eg void cursor(int &x, int &y) are C++ only.

That's pretty much all you need to know, though run code through a C
compiler if you want to use the common subset. Also overloading functions right?
This is very arguable. By declaring a C file with a few public functions and
a lot of static functions you can have something that is actually more
encapsulated than a C++ class. Would you please give me some more informations? I'm not very familiar
with public and static functions in C. Is there any webpage describe
how to use them to get a good design?
There is a difference between programming with objects, and object-oriented
programming. C programs using objects, for instance a structure that is
declared in a file, and with functions that operate on it, are common and
work well. It is possible to do object-orientation in C, where the objects
have relationships with each other, so all our "line" objects have a common
"getlength() method. However it normally a mistake because the syntax of
setting up function pointers and nested structures and the like gets so
horrible. That's why C++ was invented

Sometimes people use "object-oriented" as a synonym for "well-designed".
Procedural programs can be just as maintainable and well-structured as
object-oriented ones.


Nov 14 '05 #14

<Pe*******@gmail.com> wrote
Would you please give me some more informations? I'm not very familiar
with public and static functions in C. Is there any webpage describe
how to use them to get a good design?

In C++ we would do something like this.

class chess
{
private char board[8][8];
bool tomove;
/*
public function to see if it is checkmate
*/
public bool checkmate(void)
{
int kingcango[8];
int i;
getkingmoves(kingcango);
for(i=0;i<8;i++)
if(kingcango[i] == 1)
break;
if(i == 8)
return true;
else
return false;
}
/* complicated private function that lists allowed moves for the king */
private void getkingsmoves(int *possibles)
{
}
}

In C we do the same thing like this.

/* chess.h */

typedef struct
{
char board[8][8];
int tomove;
} CHESSBOARD;

int checkmate(CHESSBOARD *chessboard);
/* chess. c */

/* this function can be acalled by anyone */
int checkmate(CHESSBOARD *chessboard)
{
int kingcango[8];

getkingsmoves(chessboard, kingcango);
/* etc */
}

/* this function can only be called by other functions in the file chess.c
*/
static void getkingsmoves(CHESSBOARD *chessboard, int *possibles)
{
/* complicated code here to list king's legal moves */
}
What this means is that we can change the function getkingsmoves() as much
as we like, just like a private C++ function, as long as we continue to
support checkmate() somehow or other.
Nov 14 '05 #15

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

Similar topics

15
by: Ron Adam | last post by:
Does anyone have suggestions on how to improve this further? Cheers, Ron_Adam def getobjs(object, dlist=, lvl=0, maxlevel=1): """ Retrieve a list of sub objects from an object. """
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
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...
0
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...
0
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,...

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.