473,779 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4655
> 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.earth link.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*s izeof *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)==si zeof(char))
*/
new=malloc(17*s izeof '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******** *********@newsr ead4.news.pas.e arthlink.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
2195
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 set is an subset of another or contain exactly the same members. Tried to do the following: s1=set() s2=set() s3=set()
29
7487
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 function will return me an array holding a random subset of integers in that range of a size that I specify So the Function would Probabaly look something like this:
2
1514
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 variable might be used or unused in a given object. For each field, there is a FieldIsValid() member function that must be called before accessing or mutating a given field. If a field is reported as not valid, it must not be accessed or mutated....
1
2714
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 relate addresses (multiple addresses); companies, contacts, and tasks to each project (one to many). My challenge lies with the task sub-form which links to the Project form through ProjID. The task record links back to the respective master...
0
1141
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 data, on the basis of the user logged in. In other words, say you have a table with a field containing a value, I would like a particular user who logs in to see modify and delete only his own data subset,
36
3893
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 memory. No way to reinterpret it as bunch of bytes * Recovery from invalid and NULL pointers other than crash * Possibility to isolate piece of code by not giving it key pointers Library used to support such safe subset must not introduce its own...
1
2329
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 parent node has 100 nodes, I want to delete nodes 10 through 75, and not nodes 5, 10, 25 etc. I have a reference to the first and the last node in the list that has to be removed. Also it's position in the list, if that helps.
148
5213
by: BillJosephson | last post by:
Want to do OOP. Does c++ have all the abilities of java, or is it some subset? Thanks...
5
11155
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(); However, I want to then select a subset of this data from within the client. I tried this: IQueryable<PenpensSubset = from p in pens select p.PenId, p.PenNumber;
0
9636
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10306
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10074
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8961
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7485
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6724
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5373
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5503
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.