Re: variadic functions



On 3 Oct, 10:17, "io_x" <a...@xxxxxxxxxxx> wrote:
"Frank" <merr...@xxxxxxxxxxxxxxxxx> ha scritto nel messaggionews:23c2ebd2-dd31-43b0-8de1-0050cc007de9@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
#include <string.h>
int main(void)
{
 int printf(const char *, ...);

in what i know here you say to the linker to find
"int printf(const char *, ...);"
that could be different from printf in <stdio.h>?

I think you (io_x) could be making the same mistake here that I did
when I first learnt C. I thought that printf was "in" stdio.h, ie that
stdio.h contained the code to do printing. This is not the case.

Headers, such as stdio.h, contain text. This text can be included into
your program, and will have the same effect as if you included that
same text yourself in your program file. In the case of printf,
stdio.h contains a prototype, so that your program knows how to call
printf properly, but it doesn't have a clue what printf actually does.

Somewhere else, for example in a file called something.lib, there is
the actual machine code for printf, and when you link the program the
linker will find this and do the right thing with it, which will
normally involve copying the code into your executable.

My first compiler had six different .LIB files, but this wasn't so
that each only covered some of the functions, the way that .h files
do. They were because the computer had a choice of six different
"memory models" which each required slightly different versions of the
functions. Each .LIB file contained all of the functions.

Hope that helps.
Paul.
.



Relevant Pages

  • Re: Include statements and compiler linking
    ... Why is it that the header file doesnt need to be linked ... linker not knowing the PATH to the header file. ... -there is function (e.g printf), ... You tell the compiler how to use the code ...
    (comp.lang.c)
  • Re: bug raport - about way of linking in c
    ... and d has a "printf" definition too (same signature ... But when one will try to link it linker ... be a source-level solution such as name spaces. ... Linker should not just fail but should just calmly ...
    (comp.lang.c)
  • Re: bug raport - about way of linking in c
    ... and d has a "printf" definition too (same signature ... On compiler level it is no problem, ... But when one will try to link it linker ... linker will fail because it will be trying to ...
    (comp.lang.c)
  • Re: program having printf() function invocation without including
    ... warning and would assume that it would return a int, ... make your call to printf() to a printfroutine in a library. ... There are some implementations on which the linker does ... reason a C compiler could not do the same thing, ...
    (comp.lang.c)
  • Re: Microchip Introduces First 16-bit Microcontroller Product Line - the PIC24
    ... >Creating a custom printf is MUCH better than using a library function ... Put the dummy_float.obj on the linker command line _before_ the ... When the linker detects the printf reference in he ...
    (comp.arch.embedded)