From 5ae84f274c4e1e9400fbd5d4aaa1d0328644a23e Mon Sep 17 00:00:00 2001 From: John McCall Date: Thu, 3 Feb 2011 10:16:40 +0000 Subject: [PATCH] Rework and embellish the C99 inline compatibility section. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124789 91177308-0d34-0410-b5e6-96231b3b80d8 --- www/compatibility.html | 47 +++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/www/compatibility.html b/www/compatibility.html index b068ec5827..b273487452 100644 --- a/www/compatibility.html +++ b/www/compatibility.html @@ -78,8 +78,9 @@

C99 inline functions

By default, Clang builds C code according to the C99 standard, -which provides different inlining semantics than GCC's default -behavior. For example, when compiling the following code with no optimization:

+which provides different semantics for the inline keyword +than GCC's default behavior. For example, consider the following +code:

 inline int add(int i, int j) { return i + j; }
 
@@ -89,11 +90,13 @@ int main() {
 }
 
-

In C99, this is an incomplete (incorrect) program because there is -no external definition of the add function: the inline -definition is only used for optimization, if the compiler decides to -perform inlining. Therefore, we will get a (correct) link-time error -with Clang, e.g.:

+

In C99, inline means that a function's definition is +provided only for inlining, and that there is another definition +(without inline) somewhere else in the program. That +means that this program is incomplete, because if add +isn't inlined (for example, when compiling without optimization), then +main will have an unresolved reference to that other +definition. Therefore we'll get a (correct) link-time error like this:

 Undefined symbols:
@@ -101,17 +104,31 @@ Undefined symbols:
       _main in cc-y1jXIr.o
 
+

By contrast, GCC's default behavior follows the GNU89 dialect, +which is the C89 standard plus a lot of extensions. C89 doesn't have +an inline keyword, but GCC recognizes it as an extension +and just treats it as a hint to the optimizer.

+

There are several ways to fix this problem:

+

All of this only applies to C code; the meaning of inline +in C++ is very different from its meaning in either GNU89 or C99.

"missing" vector __builtin functions

-- 2.40.0