Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > C as a Subset of C++ (or C++ as a superset of C)

Thread Tools

C as a Subset of C++ (or C++ as a superset of C)

Alf P. Steinbach
Posts: n/a
On 04.09.2012 12:47, David Brown wrote:
> On 03/09/2012 19:43, Richard Damon wrote:
>> On 9/3/12 4:21 AM, David Brown wrote:
>>> On 01/09/2012 15:39, Bo Persson wrote:
>>>> Yes, the same index in two vectors can alias. Different index cannot.
>>> That doesn't make sense. Are you saying that for two vectors v1 and v2,
>>> v1[10] and v2[10] can alias but v1[10] and v2[11] cannot?

>> v1 and v2 can be references to the same vector, and thus their
>> corresponding elements alias. Since a vector has exclusive use of its
>> "array" member storing its content, and has no operations that can yield
>> a "sub vector" that references a partial section of the vector, there is
>> no way for v1[10] and v2[11] to point to the same item.
>> This is opposed to a built in array (passed via pointers) where v1 could
>> have been set to &v2[1] and thus v1[10] and v2[11] alias.

> OK, I see that point now.
> However, while you (and now I) can understand that, I can't see any way
> for the /compiler/ to know and take advantage of that. There is no way
> to tell the compiler that v1[10] and v2[11] are in different places.

One way that the compiler is informed, is via the C++ standard.

Which as opposed to the C standard, specifies a lot of higher level
types in detail.

However, even in C some higher level issues that are specified by the
standard and cannot easily or at all be inferred from the code itself,
such as correspondence between fprintf format strings and arguments, is
now usually checked by the compiler. We just have computational power to
spare, so that the previously "costly" checking that was previously in a
separate program called "lint", is now usually just part of the compiler
proper. And with C++ a lot more is specified by the standard, than with
C -- after all, the C++ standard /includes/ the C standard.

Another way that the compiler is informed, is via C++ access
restrictions and construction guarantees, plus rules about Undefined
Behavior for code that does Unholy Things. However, to take advantage of
that the compiler would have to do some higher level data flow and
accessibility analysis. I think that it's doubtful that current
compilers do that (because it's so easy for compiler writers to get
stuck in lower level issues of parsing and parallelism and such, issues
that were solved 50 years ago but that freshly graduated don't even know
about), but as James Bond reportedly remarked, never say never.


Cheers & hth.,

- Alf

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
C as a Subset of C++ (or C++ as a superset of C) Ansel C Programming 191 12-17-2012 11:11 PM
Newbie: Are Ruby regexp's a subset, superset, or equal to Perl's? Harry Ruby 12 09-23-2009 09:45 PM
Function to apply superset of arguments to a function Andrey Fedorov Python 9 09-10-2009 03:36 AM
subset of data using dataview?? Guoqi Zheng ASP .Net 2 01-19-2004 01:54 PM
Frighteners superset, any news? Grand Inquisitor DVD Video 0 11-20-2003 03:02 AM