Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Implementation of language features

Reply
Thread Tools

Implementation of language features

 
 
W Karas
Guest
Posts: n/a
 
      03-11-2013
Is there a reference (besides the ARM and hopefully consisting of WWW page(s).) that outlines possible implementations (that is, generated object code) of C++ features? Something to point an experience C programmer to in response to comments like "I think calling a virtual function must involve a hash table lookup" or "I don't see how exception handling could not have execution time overhead even when no exceptions are thrown".
 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      03-11-2013
W Karas wrote:

Please do something about your line length!

> Is there a reference (besides the ARM and hopefully consisting of WWW
> page(s).) that outlines possible implementations (that is, generated
> object code) of C++ features? Something to point an experience C
> programmer to in response to comments like "I think calling a virtual
> function must involve a hash table lookup" or "I don't see how
> exception handling could not have execution time overhead even when
> no exceptions are thrown".


There isn't any definitive implementation standard.

There are a limited number of possible solutions for exceptions, but
each compiler has it's own implementation. Optimisation can also
obscure or remove details like virtual function calls.

--
Ian Collins
 
Reply With Quote
 
 
 
 
W Karas
Guest
Posts: n/a
 
      03-11-2013
On Monday, March 11, 2013 6:45:25 PM UTC-4, Ian Collins wrote:
> W Karas wrote:
>
>
>
> Please do something about your line length!
>
>
>
> > Is there a reference (besides the ARM and hopefully consisting of WWW

>
> > page(s).) that outlines possible implementations (that is, generated

>
> > object code) of C++ features? Something to point an experience C

>
> > programmer to in response to comments like "I think calling a virtual

>
> > function must involve a hash table lookup" or "I don't see how

>
> > exception handling could not have execution time overhead even when

>
> > no exceptions are thrown".

>
>
>
> There isn't any definitive implementation standard.
>
>
>
> There are a limited number of possible solutions for exceptions, but
>
> each compiler has it's own implementation. Optimisation can also
>
> obscure or remove details like virtual function calls.
>
>
>
> --
>
> Ian Collins


I believe there is a "model" approach for exception handling with no time overhead if no exception is thrown. It is based on generating a lookup table where the key is the return address found on the stack during stack unwind. The result of the table lookup is the address of a function that will properly destroy the known set of objects that will be active when that return address is present in the call stack.
 
Reply With Quote
 
Tiib
Guest
Posts: n/a
 
      03-12-2013
On Tuesday, 12 March 2013 10:10:18 UTC+2, Christian Gollwitzer wrote:
> Am 11.03.13 23:51, schrieb Stefan Ram:
> > W Karas <(E-Mail Removed)> writes:
> >> Is there a reference (besides the ARM and hopefully
> >> consisting of WWW page(s).) that outlines possible
> >> implementations (that is, generated object code) of C++
> >> features?

> >
> > Maybe I may follow that with my similar question:
> >
> > GCC is open source, so its source code should
> > be available. A part of it should be the source for
> > GCC's C++ standard library written in C++ itself
> > (well, maybe in the GCC dialect of it!). Does anyone
> > already know where to find this, before I start to
> > search it myself? Or/And possibly for Clang, too?

>
>
> Gcc's standard library is called libstdc++ and has it's own page:
>
> http://gcc.gnu.org/libstdc++/
>
> It's written there that libstdc++ is now part of gcc. So simply download
> a copy of the source of gcc.
>
> clang++ uses by default libstdc++, too (on OSX), but they have
> developped there own version:
>
> http://libcxx.llvm.org/


Thanks, Christian, you were very helpful. I suspect however that Stefan
was being sarcastic with his counter-question. Those sites are among first
hits when attempting to search for them.
 
Reply With Quote
 
88888 Dihedral
Guest
Posts: n/a
 
      03-12-2013
Stefan Ram於 2013年3月12日星期二UTC+8上午6時51分39秒 寫道:
> W Karas <(E-Mail Removed)> writes:
>
> >Is there a reference (besides the ARM and hopefully

>
> >consisting of WWW page(s).) that outlines possible

>
> >implementations (that is, generated object code) of C++

>
> >features?

>
>
>
> Maybe I may follow that with my similar question:
>
>
>
> GCC is open source, so its source code should
>
> be available. A part of it should be the source for
>
> GCC's C++ standard library written in C++ itself
>
> (well, maybe in the GCC dialect of it!). Does anyone
>
> already know where to find this, before I start to
>
> search it myself? Or/And possibly for Clang, too?

As far as I know, an assembler and a C compiler are implemented first
for some new CPU instruction set, then one can get the CPP compiler
in the BSD or LINUX platforms.
 
Reply With Quote
 
W Karas
Guest
Posts: n/a
 
      03-12-2013
On Tuesday, March 12, 2013 7:14:26 AM UTC-4, Tiib wrote:
> On Tuesday, 12 March 2013 10:10:18 UTC+2, Christian Gollwitzer wrote:
>
> > Am 11.03.13 23:51, schrieb Stefan Ram:

>
> > > W Karas <(E-Mail Removed)> writes:

>
> > >> Is there a reference (besides the ARM and hopefully

>
> > >> consisting of WWW page(s).) that outlines possible

>
> > >> implementations (that is, generated object code) of C++

>
> > >> features?

>
> > >

>
> > > Maybe I may follow that with my similar question:

>
> > >

>
> > > GCC is open source, so its source code should

>
> > > be available. A part of it should be the source for

>
> > > GCC's C++ standard library written in C++ itself

>
> > > (well, maybe in the GCC dialect of it!). Does anyone

>
> > > already know where to find this, before I start to

>
> > > search it myself? Or/And possibly for Clang, too?

>
> >

>
> >

>
> > Gcc's standard library is called libstdc++ and has it's own page:

>
> >

>
> > http://gcc.gnu.org/libstdc++/

>
> >

>
> > It's written there that libstdc++ is now part of gcc. So simply download

>
> > a copy of the source of gcc.

>
> >

>
> > clang++ uses by default libstdc++, too (on OSX), but they have

>
> > developped there own version:

>
> >

>
> > http://libcxx.llvm.org/

>
>
>
> Thanks, Christian, you were very helpful. I suspect however that Stefan
>
> was being sarcastic with his counter-question. Those sites are among first
>
> hits when attempting to search for them.


I guess I was not clear, I'm looking for summary descriptions in English accompanied by figures and/or bits of code. I think most people would find this preferable to reading compiler code and reverse-engineering the key strategies involved.
 
Reply With Quote
 
Stefan Ram
Guest
Posts: n/a
 
      03-12-2013
W Karas <(E-Mail Removed)> writes:
>I guess I was not clear, I'm looking for summary descriptions
>in English


http://www.phoronix.com/scan.php?pag...tem&px=MTI4NDU

 
Reply With Quote
 
Jorgen Grahn
Guest
Posts: n/a
 
      03-12-2013
On Tue, 2013-03-12, Scott Lurndal wrote:
> W Karas <(E-Mail Removed)> writes:
>>Is there a reference (besides the ARM and hopefully consisting of WWW page(=
>>s).) that outlines possible implementations (that is, generated object code=
>>) of C++ features? Something to point an experience C programmer to in res=
>>ponse to comments like "I think calling a virtual function must involve a h=
>>ash table lookup" or "I don't see how exception handling could not have exe=
>>cution time overhead even when no exceptions are thrown".

>
> The C++ ABI defines several areas that are relevent to interoperability on
> Unix systems - including the vtable layout and format.
>
> http://mentorembedded.github.com/cxx-abi/
> http://mentorembedded.github.com/cxx-abi/abi-eh.html
>
> this applies to both itanium and x86_64 systems.
>
> A good C programmer shouldn't feel uncomfortable disassembling code and
> poking around in the guts of a program to see what the the compiler is
> generating.


I suspect that W Karas' C programmers are of the kind who think it's
up to *him* to disprove their home-made theories about how C++ must
work ...

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
 
Reply With Quote
 
Dombo
Guest
Posts: n/a
 
      03-12-2013
Op 11-Mar-13 23:39, W Karas schreef:
> Is there a reference (besides the ARM and hopefully consisting of WWW
> page(s).) that outlines possible implementations (that is, generated
> object code) of C++ features? Something to point an experience C
> programmer to in response to comments like "I think calling a virtual
> function must involve a hash table lookup" or "I don't see how
> exception handling could not have execution time overhead even when
> no exceptions are thrown".


If the performance really matters and I really want to understand what
is going on I usually inspect the assembly output of the compiler and/or
step though the code with the debugger in disassembly mode.

Inspecting the assembly output can lead to sometimes surprising
insights. I see too often that people resort to tricks that make the
code hard to understand and/or brittle because they _believe_ it will
run more efficiently without bothering to actually measure it or
actually checking how it affects the code being generated. More often
than not the hack is no more efficient and quite often even less
efficient than the straightforward implementation.

There are many variables, such as the compiler, (optimization) settings
and the code being compiled, that affect what kind of code will be
generated. For example for virtual functions a vtable is typically used
(I have never seen a C++ compiler that used hash tables for virtual
functions, nor do I see any benefit with that approach), but sometimes
the compiler can skip the vtable lookup if knows at compile time exactly
which function is going to be called, it might even inline that function
in that case.

That being said the following articles should give some insight how
virtual functions are typically done by C++ compilers:
http://en.wikipedia.org/wiki/Virtual_method_table
http://tinydrblog.appspot.com/?p=89001

For exception handling the articles below may give you some insight how
C++ compilers may implement this feature:
http://preshing.com/20110807/the-cos...ption-handling
http://www.systemcall.org/blog/2010/...ndling-in-cpp/
 
Reply With Quote
 
woodbrian77@gmail.com
Guest
Posts: n/a
 
      03-12-2013
On Tuesday, March 12, 2013 8:10:18 AM UTC, Christian Gollwitzer wrote:
> clang++ uses by default libstdc++, too (on OSX), but they have
>
> developped there own version:
>
>
>
> http://libcxx.llvm.org/
>


I'm building clang ...
The getting started page says that make "builds both
LLVM and Clang for debug mode." Why do I want debug
mode? How to build it without debug stuff? Tia.

Brian
Ebenezer Enterprises - Proverbs 3:5,6.
http://webEbenezer.net



 
Reply With Quote
 
 
 
Reply

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
Are c++ features a subset of java features? BillJosephson C++ 148 01-27-2007 11:40 AM
language features! Sean C++ 6 03-24-2006 08:19 PM
Language features 5460lqh@163.com C++ 18 11-04-2005 03:05 PM
Two favorite features of C++, and over-rated, and misued features Jonathan Mcdougall C++ 2 11-03-2005 06:22 PM
[ANN] IDE with support for upcoming Java 1.5 language features Omnicore Software Java 1 09-29-2003 10:14 AM



Advertisments