External Linkage

External Linkage - External Linkage One of the common...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
External Linkage One of the common issues that always comes up with programming languages is how to mix code written in one language with code written in another. For example, suppose that you're writing C++ code and wish to call C functions. A common case of this would be to access C functions that manipulate C-style strings, for example strcmp() or strlen(). So as a first try, we might say: extern size_t strlen(const char*); and then use the function. This will work, at least at compile time, but will probably give a link error about an unresolved symbol. The reason for the link error is that a typical C++ compiler will modify the name of a function or object ("mangle" it), for example to include information about the types of the arguments. As an example, a common scheme for mangling the function name strlen(const char*) would result in: strlen__FPCc There are two purposes for this mangling. One is to support function overloading. For example, the following two functions cannot both be called "f" in the object file
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/27/2012 for the course CS 251 taught by Professor Staff during the Fall '08 term at Purdue.

Page1 / 2

External Linkage - External Linkage One of the common...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online