- To: Timothy Madden <terminatorul@xxxxxxxxx>
- Subject: Re: One-definition rule for inline functions
- From: Jonathan Wakely <jwakely.gcc@xxxxxxxxx>
- Date: Thu, 8 Mar 2012 01:10:50 +0000
- Cc: gcc-help@xxxxxxxxxxx
- Comment: DKIM? See http://www.dkim.org
- Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1331773872; h=Comment: DomainKey-Signature:Received:Received:Received:Received: MIME-Version:Received:Received:In-Reply-To:References:Date: Message-ID:Subject:From:To:Cc:Content-Type: Content-Transfer-Encoding:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=mKqQavKjoConpkEoKFbF9cNZq4M=; b=W7+QRR44iS3tIW5 Kn48ymnHrLSbHQsjQ60DXNf8U907OFMy6Xv6oFcm10QONBkm9qQbsfxBujeQZUPB r/Hki71As2az4RNSO/yOX5AHKFFp+ZXaCr8ED1RZ2efNDVjvNjliUliUY7ikdXCp +VnpF4ZLC6jz3n3T+0EqTMlBNbPs=
- In-reply-to: <jj90f0$5qh$1@dough.gmane.org>
On 8 March 2012 01:02, Timothy Madden wrote:
> Hello
>
> I have an inline function like this:
>
> void draw_unit_vector()
> {
> // some large code here
> // ...
>
> LineTo(1, 1);
> }
>
> in two translation units A and B.
>
> Now if the function is large enough it is still compiled and called, and not
> inlined.
>
> The LineTo() function has two overloads:
> - translation unit A only needs the float version:
> LineTo(float x, float y);
> and declares it before it includes the inline function.
> - translation unit B uses both int and float versions:
> LineTo(int x, int y);
> LineTo(float x, float y);
> and declares them before it includes the inline function.
>
> The same inline function would call LineTo(float, float) in source A, but
> would call LineTo(int, int) in source B. And it so happens that the two
> overloads for LineTo() are quite different, the int version is for text-mode
> only, while the float version is for graphics mode.
>
> By the C++ standard this case is a clear violation of the one-definition
> rule, and users should take good care to avoid it.
>
> My question is: what does g++ do in such case ?
>
> Does it compile two different draw_unit_vector() functions from the same
> inline function definition ?
Yes, then discards one of the definitions, see
http://gcc.gnu.org/onlinedocs/gcc/Vague-Linkage.html
[Linux C Programming]
[Linux Kernel]
[eCos]
[Fedora Development]
[Fedora Announce]
[Autoconf]
[The DWARVES Debugging Tools]
[Yosemite Campsites]
[Yosemite News]
[Linux GCC]