473,385 Members | 1,764 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,385 software developers and data experts.

C and C++ - The Difference Please?

I am new to programming in the C / C++ language and I am using a mixture of
online materials plus a small collection of C and C++ books.

What I basically want to know is how do I know if something I am learning is
from the C Language or the C++ Language and should I avoid mixing the two.

I am under the impression that C++ is the successor of C but I would imagine
at the same time there are some functions that have become obsolete under
C++ from the C language and I want to avoid using them.

I am developing on a Linux machine and compiling using gcc and simply using
VIM as a text editor for my source code.

--

Kind Regards,

Paul Woodward
Jul 19 '05 #1
7 3280
On Sat, 19 Jul 2003 14:34:17 +0100, "Paul Woodward" <no*****@newsgroups.com> wrote:
I am new to programming in the C / C++ language and I am using a mixture of
online materials plus a small collection of C and C++ books.

What I basically want to know is how do I know if something I am learning is
from the C Language or the C++ Language
There are some subtle syntactical and semantic differences, but for these
you'll just have to assume that what you see in a C++ book or article is
proper C++. Don't rely on the compiler. Many compilers allow C constructs,
such as (C99) dynamic size arrays, in C++ code.

C doesn't have classes or templates, so all classes and templates are C++.

Regarding library functions: if you can put "std::" in front of the name,
then it's C++. However, the opposite is not necessarily true. For example,
"assert" is implemented as a macro (you cannot put "std::" in front), but
is available in both C and C++.
and should I avoid mixing the two.
Yes, you should. In particular, avoid C memory allocation (malloc and
friends). And wherever practical, use C++ standard library classes such
as std::string and std::vector instead of raw arrays and pointers.

As a novice, avoid C i/o such as printf; use C++ std::cout and friends
instead.

Don't use old-style C headers such as
#include <stddef.h>
but use the C++ wrappers such as
#include <cstddef>

I am under the impression that C++ is the successor of C but I would imagine
at the same time there are some functions that have become obsolete under
C++ from the C language and I want to avoid using them.
Not many, but see above.
I am developing on a Linux machine and compiling using gcc and simply using
VIM as a text editor for my source code.


g++ (gcc) is one of the compilers that by default allows C99 constructs
in C++ code. That doesn't mean it's a bad compiler. On the contrary,
but it's a good idea to keep that in mind, and check if there are options
you can use to restrict the compiler to standard C++.

Jul 19 '05 #2
Alf P. Steinbach wrote:
On Sat, 19 Jul 2003 14:34:17 +0100, "Paul Woodward" <no*****@newsgroups.com> wrote:
[great suggestion snipped]
g++ (gcc) is one of the compilers that by default allows C99 constructs
in C++ code. That doesn't mean it's a bad compiler. On the contrary,
but it's a good idea to keep that in mind, and check if there are options
you can use to restrict the compiler to standard C++.


One additional suggestion is the version of the gcc - get the latest
(3.3) and get gcc-3.4 when it comes out.

The gcc-2.9x C++ compiler is lacking.

G

Jul 19 '05 #3
al***@start.no (Alf P. Steinbach) wrote in message news:<3f****************@News.CIS.DFN.DE>...
g++ (gcc) is one of the compilers that by default allows C99 constructs
in C++ code. That doesn't mean it's a bad compiler. On the contrary,
but it's a good idea to keep that in mind, and check if there are options
you can use to restrict the compiler to standard C++.


In particular, the -pedantic and probably -ansi options.

Tommy McDaniel
Jul 19 '05 #4

"Paul Woodward" <no*****@newsgroups.com> wrote in message
news:3f***********************@news.dial.pipex.com ...
I am new to programming in the C / C++ language and I am using a mixture of online materials plus a small collection of C and C++ books.

What I basically want to know is how do I know if something I am learning is from the C Language or the C++ Language and should I avoid mixing the two.

I am under the impression that C++ is the successor of C but I would imagine at the same time there are some functions that have become obsolete under
C++ from the C language and I want to avoid using them.

I am developing on a Linux machine and compiling using gcc and simply using VIM as a text editor for my source code.

--

Kind Regards,

Paul Woodward


To start off with read the classic programming text for "C" : "The C
Programming Language" by Kernighan and Ritchie.
All "C" programs are C++ programs. Since essentially C++ is a superset of
"C" with object-oriented syntax and semantics added,
mainly objects and classes. ( C uses structs).

Then for a one of the best tutorial reference , refer to ( borowed from a
library ) or get yourself a copy of "The C++ Programming Language"
by Bjarne Stroustrup( the inventor of C++). It is a bit hard to read at
first, so you may refer to a less terse C++ tutorial
book , to help break you into the Strousop book. Depending on your
background, choose for yourself a beginner
C++ tutorial book(suitable for your understanding level), because I dont
know your programming history or coding experience.
Both books mentioned above are quite easy to find both have white covers
Use pico , advanced editor or xemacs as programming editor for editing
source code ( as your confidence grows.) vim or vi
is a bit hard for a Unix or Linux beginner.

Regards,
Gavin
Jul 19 '05 #5
On Sun, 20 Jul 2003 21:54:53 +0800, "Govindan Chandran" <go****@pacific.net.sg> wrote:
All "C" programs are C++ programs.


Otherwise good advice, but the above is incorrect.

It's not difficult to write code that compiles as both C and C++,
which means writing in the common subset of the two languages.

But C is not a proper subset of C++.

Jul 19 '05 #6
> But C is not a proper subset of C++.

That's especially true after C99. The following things are some of the
features *not* supported in C++ but are in the new C standard
(according to Steven Prata, C primer plus, 4th ed.)

* Restricted pointers,
* Variable-length arrays
* Flexible array members
* Macros with a variable number of arguments

and more
Jul 19 '05 #7
Stroustrup had some very informative articles on this subject in the C++
User's Journal (http://www.cuj.com/); they should still be available online,
so I won't summarize them here.
Jul 19 '05 #8

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

Similar topics

10
by: David | last post by:
what's the differences between: int main(int argc,char* argv){ ... } and: int main(int argc,char** argv){ ...
24
by: wwj | last post by:
Hi ,all I want to know the difference between char a and char *p=new char and the difference between the heap and the stack ,and if the char a is corresponding to the stack in MEMORY,and char...
6
by: Ashish Sheth | last post by:
Hi All, In C#, How can I get the difference between two dates in number of months? I tried to use the Substract method of the DateTime class and it is giving me the difference in TimeSpan,From...
6
by: Mark Kamoski | last post by:
Hi Everyone-- Please help. What is the difference between a Field and a Property? Here is the context. In the VS.NET 2002 documentation, in the "String Members" section, we have the...
5
by: kai | last post by:
Hi, In ASP.NET , what is the difference between OnClick and Click events for a button? Because we have button click event, it can trigger events, why we still need OnClick? Please help. ...
18
by: Vasileios Zografos | last post by:
Hello, can anyone please tell me if there is any difference between the two: double Array1; and
7
by: anuradhathakur.it | last post by:
Is there any difference between i++ & i=i+1... I mean, I read somewhere that i++ is faster then i=i+1.. But as both of them is performing same operations....how can one be faster than another...
12
by: Petronius | last post by:
Hallo, does anyone have an idea how to implement difference lists in Javascript? Thanks allot in advance
3
by: cheguashwini | last post by:
Hi I have a problem. I have two tables...table1 and table2. table1 has the column latitude and sno(serial number) and table2 has the column lat and sno(serial number) . i have to find the...
2
by: qwedster | last post by:
Folks! What is the difference between PostBack and Callback ( !IsPostBack and if(!IsCallback)) Like in the following Code Snippet: protected void Page_Load(object sender, EventArgs...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.