This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: multiple defintions error



thanks.  I've changed the code base to extern inline.  I don't see much
change in the compiled code size though.  I don't know much about
performance.  However, I don't understand another aspect of C.

I get some memory say 64 bytes using (unsigned char *)


    unsigned char *p = (unsigned char *) calloc( 1, 64 )

now I map the following structures on top of this memory.

    struct dummy1
    {
      short int x;
      short int y;
    }

    struct dummy2
    {
      char string1[16];
      char string2[16];
    }

if I do the following mapping it doesnt work.

    struct dummy1 *d1 = (struct dummy1 *) p;

    struct dummy2 *d2 = (struct dummy2 *) (d1 + sizeof( struct dummy1 ));

what works is

    struct dummy1 *d1 = (struct dummy1 *) p;

    struct dummy2 *d2 = (struct dummy2 *) (p + sizeof( struct dummy1 ));

Now I can understand that the second version is cleaner but I can't find a
reason as to why the first version is wrong.

The way I see it is that I'm mapping a structure onto a memory space, it
shouldn't generate segementation fault because it is valid memory on the
heap.  It shouldn't matter how I access it, meaning move the d1 pointer 16
bytes forward i.e. till it's end, and map `struct dummy2' on the remaing
bit verses moving p pointer 16 bytes forward and mapping `struct dummy2`.

Or am I looking at the wrong issue all together.  Maybe it was something
else wrong and I'm attributing it to this?  Any ideas!


On Tue, 3 Oct 2000 amylaar@cygnus.co.uk wrote:

> > extern inline would mean that the function is to be inlined but is
> > implemented in some other file.
> 
> It means it is to be inlined if possible, but if it can't be inlined -
> that could be because it is too big, contains constructs that defy inlining,
> or because it's a recursive call - don't provide an out-of-line copy
> of this function, becaus it is provided in an external file.
> 

-- 
Atif Shahab
Network Engineer
ViewInternet.com
Office Tel: +65 232 8877
DID: +65 232 8625
Office Fax: +65 232 8638
www.viewinternet.com.sg

******************************************************
Check your email from anywhere using www.viewemail.com
******************************************************


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]