public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: Amittai Aviram <amittai.aviram@yale.edu>
Cc: gcc-help@gcc.gnu.org
Subject: Re: GCC Internals: built-in functions?
Date: Sun, 30 Jan 2011 21:01:00 -0000	[thread overview]
Message-ID: <AANLkTi=wMQx1xxDGuRgkJQ+FvR0e6UKUwKWQT1npQ_z3@mail.gmail.com> (raw)
In-Reply-To: <D4CC12B2-BBC2-4B21-8B20-C694BEAE84B6@yale.edu>

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_Architecture_3_4
>
> I found the following in the "GCC Initialization" section:
>
> "GCC built-in functions are the functions that are evaluated at compile time. For example, if the size argument of a strcpy() function is a constant then GCC replaces the function call with the required number of assignments."
>
> I was curious about this, so I tried compiling to assembly (-S) a very simple program:
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
>
> int main(void) {
>
>        char s1[0x10];
>        char * s0 = "HELLO";
>        strcpy(s1, s0);
>        printf("%s %s\n", s0, s1);
>        return EXIT_SUCCESS;
> }
>
> But the resulting assembly code simply calls strcpy with the two arguments, just as I would have expected had I not read the above sentence:
>
>        movq    $.LC0, -40(%rbp)
>        movq    -40(%rbp), %rdx
>        leaq    -32(%rbp), %rax
>        movq    %rdx, %rsi
>        movq    %rax, %rdi
>        call    strcpy
>
> (Here, .LC0 labels the string "HELLO".)
>
> So what does that sentence actually mean and what am I missing?  Thanks!

strcpy has no 'size' parameter, I assume it's meant to say strncpy

  reply	other threads:[~2011-01-30 20:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-30 20:50 Amittai Aviram
2011-01-30 21:01 ` Jonathan Wakely [this message]
2011-01-30 21:07   ` Amittai Aviram
2011-01-30 21:28     ` Jonathan Wakely
2011-01-31  4:53       ` Amittai Aviram

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='AANLkTi=wMQx1xxDGuRgkJQ+FvR0e6UKUwKWQT1npQ_z3@mail.gmail.com' \
    --to=jwakely.gcc@gmail.com \
    --cc=amittai.aviram@yale.edu \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).