Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > C/C++ abstraction layer

Reply
Thread Tools

C/C++ abstraction layer

 
 
W Karas
Guest
Posts: n/a
 
      01-30-2013
On Monday, January 28, 2013 2:21:07 PM UTC-5, jis wrote:
> Hello guys,
>
>
>
> please help me with following problem.
>
>
>
> I have a.c which includes a.h
>
> i have b.c which includes b.h
>
> i have b.h which includes c.h (c.lib included)
>
>
>
> a.c uses some functions which are defined in c.lib.
>
> so i included b.h in a.h therby including c lib functions.
>
>
>
> but iam writing something like hardware abstraction layer.
>
> I dont want a.c access c.lib functions directly.
>
> One way is to include c.h in b.c instead of b.h
>
>
>
> What would be the standard pro way to do this.
>
>
>
> Please help me. (using visual studio 2010 express on windows 7)


An obvious answer is to add "wrapper" function to b.c that call the needed functions in the c library. But I always find it annoying when there is a performance penalty for limiting the visibility of declarations.

I wonder if there are any compilers that detect cases a wrapper function can be correctly implemented by a simple jump to the function being "wrapped".. I'm guessing only the very best compilers do this, if any.

I'd be in favor of an explicit language construct that would allow defininga function (non-inline) as an alias of another declared function. Doesn'tseem like this would impose a big burden on the linker. The linker would have to error check that the two functions had matching argument lists (theusual way, based on name decoration). The address backpatching by the linker required to implement this seems comparable in complexity to currently necessary address backpatching.
 
Reply With Quote
 
 
 
 
Tobias Müller
Guest
Posts: n/a
 
      01-30-2013
W Karas <(E-Mail Removed)> wrote:
> I wonder if there are any compilers that detect cases a wrapper function
> can be correctly implemented by a simple jump to the function being
> "wrapped". I'm guessing only the very best compilers do this, if any.


That's a special case of tail call optimization:
If the last operation in a function is calling another function (and
returning its value), the existing stack frame can be reused and the call
can be replaced by a jump.
In this case it is especially easy. Since the parameters are just
forwarded, the stack frame does not have to be modified at all. But in
general this is not necessary for tail call optimization.

However, TCO is not so often seen in the C/C++ world. In C++ the last
operation in a function tends to be a destructor call, which limits the
applicability.

In functional programming however, TCO is often even required by the
language standard. It's important for recursive functions, otherwise the
stack will overflow rather quickly.

Tobi
 
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
Database Abstraction Layer And/Or ORM BJ Dierkes Python 1 09-24-2007 11:28 AM
business layer, data access layer , presentation layer for asp.net using C#.net Dhananjay ASP .Net 1 12-18-2006 11:35 PM
memmove: works on C's abstraction layer? or no? Kobu C Programming 18 07-23-2006 09:54 PM
Abstraction layer between C and CPU Luke Wu C Programming 30 02-05-2005 01:15 AM
Re-install corrupt HAL.DLL (hardware abstraction layer) Mym Computer Support 3 07-12-2004 04:39 PM



Advertisments