help regarding linking

Patrick Percot ppercot@free.fr
Sat Nov 27 12:22:00 GMT 2004


On Sat, 27 Nov 2004 00:14:27 -0500, rganti@nd.edu wrote

> 
> Hi,

Hi Radha,


>       I am a newbie at using gcc.  I wanted to write functions and the main file
> in different files
> 
>  I am using the following to compile
> gcc -c file1.c
> gcc  -c file2.c
> gcc file1.o file2.o
> a.out
> 2.00000 1.90000
> 
> I am not able to understand why that is the output. But if write the
> function to_print in file1.c and compile, it works normally.
> If I replace all floats  in both files by double it works
> 
> What is happening? Am I compiling them wrong. 

When  there is  no prototype  for a  function, floats  are automatically
converted  to double  when they  are transmitted  as parameters  to this
function. So, their  size is modified : you can  use the operator sizeof
to compute the size of each type on your machine. 

As your  function to_print  waits for float  (4 bytes) and  the compiler
transmits double (8 bytes),  the function to_print actually prints parts
of the first variable. 

Representation of the Stack :

What is actually on the stack
------------------------------------------------------------------------
|                a                |                 b                  |
------------------------------------------------------------------------

What to_print expects to find
-----------------------------------
|       a        |      b         |
-----------------------------------


[..Zappé 36 lignes et 449 caractères..]

À+
PP
-- 
Groupe Morbihannais d'Utilisateurs de Logiciels Libres http://www.tuxbihan.org
GPG fingerprint = 1A4F E154 3D2C A20E E4CA  A543 7951 C5C2 E44A A0B5

Patrick Percot.



More information about the Gcc-help mailing list