From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7562 invoked by alias); 30 Jan 2011 20:57:31 -0000 Received: (qmail 7554 invoked by uid 22791); 30 Jan 2011 20:57:30 -0000 X-SWARE-Spam-Status: No, hits=-0.8 required=5.0 tests=AWL,BAYES_50,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,TW_CP,TW_OV X-Spam-Check-By: sourceware.org Received: from mail-iy0-f175.google.com (HELO mail-iy0-f175.google.com) (209.85.210.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 30 Jan 2011 20:57:24 +0000 Received: by iyj18 with SMTP id 18so4567798iyj.20 for ; Sun, 30 Jan 2011 12:57:22 -0800 (PST) MIME-Version: 1.0 Received: by 10.42.174.198 with SMTP id w6mr6901564icz.135.1296421042733; Sun, 30 Jan 2011 12:57:22 -0800 (PST) Received: by 10.42.230.66 with HTTP; Sun, 30 Jan 2011 12:57:22 -0800 (PST) In-Reply-To: References: Date: Sun, 30 Jan 2011 21:01:00 -0000 Message-ID: Subject: Re: GCC Internals: built-in functions? From: Jonathan Wakely To: Amittai Aviram Cc: gcc-help@gcc.gnu.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2011-01/txt/msg00471.txt.bz2 On 30 January 2011 20:45, Amittai Aviram wrote: > On this GCC Internals page > > http://en.wikibooks.org/wiki/GNU_C_Compiler_Internals/GNU_C_Compiler_Arch= itecture_3_4 > > I found the following in the "GCC Initialization" section: > > "GCC built-in functions are the functions that are evaluated at compile t= ime. For example, if the size argument of a strcpy() function is a constant= then GCC replaces the function call with the required number of assignment= s." > > I was curious about this, so I tried compiling to assembly (-S) a very si= mple program: > > #include > #include > #include > > int main(void) { > > =A0 =A0 =A0 =A0char s1[0x10]; > =A0 =A0 =A0 =A0char * s0 =3D "HELLO"; > =A0 =A0 =A0 =A0strcpy(s1, s0); > =A0 =A0 =A0 =A0printf("%s %s\n", s0, s1); > =A0 =A0 =A0 =A0return EXIT_SUCCESS; > } > > But the resulting assembly code simply calls strcpy with the two argument= s, just as I would have expected had I not read the above sentence: > > =A0 =A0 =A0 =A0movq =A0 =A0$.LC0, -40(%rbp) > =A0 =A0 =A0 =A0movq =A0 =A0-40(%rbp), %rdx > =A0 =A0 =A0 =A0leaq =A0 =A0-32(%rbp), %rax > =A0 =A0 =A0 =A0movq =A0 =A0%rdx, %rsi > =A0 =A0 =A0 =A0movq =A0 =A0%rax, %rdi > =A0 =A0 =A0 =A0call =A0 =A0strcpy > > (Here, .LC0 labels the string "HELLO".) > > So what does that sentence actually mean and what am I missing? =A0Thanks! strcpy has no 'size' parameter, I assume it's meant to say strncpy