Re: help regarding linking

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, 27 Nov 2004 00:14:27 -0500, rganti@xxxxxx 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.


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux