This is the mail archive of the gcc-bugs@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: Weird pointer declaration bug


* Karl-Max Wagner (karlmax@oberland.net) [20000828 00:17]:

> It seems that none of the pointer variables declared in function
> foo are assigned proper memory space - in both cases 0x0 is
> shown as address. Subsequent attempt to assign values to them
> result in a segfault.

Wellcome to the world of C :) That's how it should be as per the standard!
You have to allocate the memory yourself. Something like:

void foo(float bar)
{
    float *a;
    float *b;
    float c;

    a = malloc(sizeof(float));
    b = &c;
    
    *a = bar;
    *b = bar;
    free(a);
}

For more information, visit a book about ISO C nearest to you or newsgroups
like comp.lang.c and comp.lang.c.moderated.

Philipp
    

-- 
Philipp Thomas <pthomas@suse.de>
Development, SuSE GmbH, Schanzaecker Str. 10, D-90443 Nuremberg, Germany

#define NINODE  50              /* number of in core inodes */
#define NPROC   30              /* max number of processes */
 	-- Version 7 UNIX for PDP 11, /usr/include/sys/param.h

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