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]
Other format: [Raw text]

[Bug c/13691] malloc returns eroneous pointer


------- Additional Comments From bording at bnl dot gov  2004-01-15 00:26 -------
Subject: Re:  malloc returns eroneous pointer

Sorry - I was careless - obviously it's a pointer. It should have been:

  double **A,**B;

  A = (double **)malloc(16000*sizeof(double *));
  B = (double **)malloc(32000*sizeof(double *));

  A[3] = (double *)malloc(1*sizeof(double));  // works fine
  B[3] = (double *)malloc(1*sizeof(double));  // crashes with a 
segmentation fault on x86_64

Jan



pinskia at gcc dot gnu dot org wrote:

>------- Additional Comments From pinskia at gcc dot gnu dot org  2004-01-15 00:17 -------
>You cannot do this:
>A = (double **)malloc(16000*sizeof(double *));
>B = (double **)malloc(32000*sizeof(double *));
>A[3] = 1.234;  // works fine
>B[3] = 1.234;  //  gives p0_23074:  p4_error: interrupt SIGSEGV: 11
>
>That will not compile anyways.  But if you change it to:
>A[3][3] = 1.234;
>this will compile but it will not work as you have not allocated what A[3] points to, go read a book 
>about C memory and pointers, no I do not know of one.
>
>  
>



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13691


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