Thread: allocate space

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    79

    allocate space

    I have to allocate this

    Code:
    char            *s,        /*IN-File name             ****/
    void            ***subs,   /*OUT -2D submatrix indices  **/
    void            **storage, /*OUT -Submatrix stored here  */
    use the code

    Code:
     *storage = (void *) my_malloc(id, *n *local_rows * datum_size);
      *subs = (void **) my_malloc (id, local_rows * PTR_SIZE);
    by using a function like this.

    Code:
    void *my_malloc( int id, int bytes)
    {
      void *buffer;
      if((buffer = malloc ((size_t) bytes)) == NULL)
        { printf ("ERROR: MALLOC FAILED FOR PROCESS %d\n", id);
          fflush (stdout);
          MPI_Abort(MPI_COMM_WORLD,MALLOC_ERROR);
        }
      return buffer;
    }
    compile and take the error

    Code:
    matr_vect_mult.c:114: error: conflicting types for ‘my_malloc’
    have u any idea whats wrong

  2. #2
    Registered User
    Join Date
    Apr 2010
    Posts
    79
    char *s is not a problem sorry for copy this the error is for *storage and *subs

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    399
    Have you declared the function my_malloc before you use it? I.e., put a prototype for it in a header file and included it in files that use the function.

  4. #4
    Registered User
    Join Date
    Apr 2010
    Posts
    79
    Hello Thanks for the reply. I did that, recompile and took a warning for the my_malloc function


    incompatible implicit declaration of built-in function ‘malloc’

    Any idea?

    Many thanks

  5. #5
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    You did not #include <stdlib.h>
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  6. #6
    Registered User
    Join Date
    Apr 2010
    Posts
    79
    yes excellent Thanks !!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  2. Process memory space
    By barboris in forum C++ Programming
    Replies: 6
    Last Post: 04-25-2008, 11:35 PM
  3. malloc allocates the same space in the memory
    By myle in forum C Programming
    Replies: 23
    Last Post: 11-20-2007, 07:52 PM
  4. Read space from the file
    By Ken JS in forum C++ Programming
    Replies: 9
    Last Post: 08-05-2007, 03:13 AM
  5. allocate no space for dynamic array~
    By black in forum C++ Programming
    Replies: 2
    Last Post: 06-11-2004, 06:28 AM