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

C is not a subset of C++?

I've seen it asserted in a few places that C is not a proper subset of
C++, but I don't understand the assertion. What things are valid C
that aren't valid C++?

Thanks.
Jul 19 '05 #1
5 4623
> I've seen it asserted in a few places that C is not a proper
subset of C++, but I don't understand the assertion.


Read this: http://www.research.att.com/~bs/3rd_compat.pdf
Jul 19 '05 #2
Oliver S. wrote:
I've seen it asserted in a few places that C is not a proper
subset of C++, but I don't understand the assertion.


Read this: http://www.research.att.com/~bs/3rd_compat.pdf


Thanks much. That was a great reference.
Jul 19 '05 #3
In article <eZ*****************@newsread4.news.pas.earthlink. net>,
Oliver Dain <od****@nospam.mindspring.com> wrote:
I've seen it asserted in a few places that C is not a proper subset of
C++, but I don't understand the assertion. What things are valid C
that aren't valid C++?


As an example, this will compile and run (but do nothing interesting)
as C, but not as C++:
--------
/*'.h' form of C headers is bad form in C++ - use <cstdlib> instead*/
#include <stdlib.h>

/*Implicit int - Valid (but deprecated) C, not valid C++*/
main()
{
/*'new' as variable name - Valid C, not valid C++*/
int *new;

/*Implicit conversion from void * - Valid C, not valid C++*/
new=malloc(42*sizeof *new);

/*Implicit conversion *to* void * is valid in both languages*/
free(new);

/*Casting malloc() - bad code in both languages
(Hides bugs like failing to #include <stdlib.h> in C,
new should be used instead of malloc in C++)
*/
/*Character constants with type int - valid C, silent bug in C++
(unless sizeof(int)==sizeof(char))
*/
new=malloc(17*sizeof 'a');

free(new);

/*Falling off the end of main() - different semantics depending on language
C90 returns unspecified exit status, C99 and C++ treat it like 'return 0'
*/
}
--------

Plus there are some more esoteric differences like different handling
of '//' comments that are unlikely to show up in code not deliberately
written to demonstrate them.

Google for 'subset' in comp.lang.c for more than you ever wanted to know
about this.
Note that if you're willing to get a bit more hand-wavey, you can
legitimately claim that the expressive power of C is a subset of the
expressive power of C++ (though this is less true with C99 than with C90);
a C program can be made into a valid C++ program with the same semantics
without any major structural changes (though there will probably be a
bunch of code-level changes that are needed).
dave

--
Dave Vandervies dj******@csclub.uwaterloo.ca
[Y]ou can write bad code that just barely works in both languages, or good
code that works only in one language -- so pick one, and write good code in
that language. --Chris Torek in comp.lang.c (crossposted to comp.lang.c++)
Jul 19 '05 #4
"Oliver Dain" <od****@nospam.mindspring.com> wrote in message
news:eZ*****************@newsread4.news.pas.earthl ink.net...
I've seen it asserted in a few places that C is not a proper subset of
C++, but I don't understand the assertion. What things are valid C
that aren't valid C++?


There's a web page devoted to answering that exact question:

http://david.tribble.com/text/cdiffs.htm

I've found it to be an excellent reference.

Regards,

Russell Hanneken
rh*******@pobox.com

Jul 19 '05 #5
Dave Vandervies wrote:
/*Implicit int - Valid (but deprecated) C, not valid C++*/
main()


Actually NOT valid C according to the latest standard. You should make
that clear here as you did in later points.

Brian Rodenborn
Jul 19 '05 #6

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

Similar topics

15
by: les_ander | last post by:
Hi, I have many set objects some of which can contain same group of object while others can be subset of the other. Given a list of sets, I need to get a list of unique sets such that non of the...
29
by: Chris Dutrow | last post by:
I searched around on the net for a bit, couldn't find anything though. I would like to find some code for a function where I input A Range Of Integers For example: Function( 1, 100 ); And the...
2
by: Dave | last post by:
Hello all, I have a class that contains a large number of discrete pieces of state information. Any combination of these member variables might be valid for a given object. Any given member...
1
by: Robert Neville | last post by:
The solution to my dilemma seems straight-forward, yet my mind has not been forthcoming with a direct route. My Project form has a tab control with multiple sub-forms; these distinct sub-forms...
0
by: Massimiliano | last post by:
Hi all, I created a database application, and created the protection setup, with users and grants. I have this problem: I would like to filter/give access & grants on a particular subset of...
36
by: Robert Vazan | last post by:
I am looking for other people's attempts to create safe subset of C and enforce it with scripts. Does anybody know about anything like this? By "safe", I mean the following: * Strongly typed...
1
by: Daniel Rucareanu | last post by:
Hello, Does anybody knows how can you delete, in just one step, not using a loop, a subset of the child nodes of a given DOM parent node? The subset will be continous, so for example, if the...
148
by: BillJosephson | last post by:
Want to do OOP. Does c++ have all the abilities of java, or is it some subset? Thanks...
5
by: Ronald S. Cook | last post by:
From my business tier (class) I get back an IQueryable<Penof data. Here is my client code that works fine: PenClass penClass = new PenClass(); IQueryable<Penpens = penClass.SelectPens(); ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.