Re: problem passing pointer array



On Jun 30, 7:51 pm, vipps...@xxxxxxxxx wrote:
On Jun 30, 7:15 pm, pereges <Brol...@xxxxxxxxx> wrote:

On Jun 30, 8:59 pm, vipps...@xxxxxxxxx wrote:

Change int ***b to int **b.
Change the 'int **b' in your main() to int *b.

Wouldn't int *b lead to an array instead of array of pointers ? I
needed array of pointers hence int **b.

Sorry, I just realized that.
The problem in your original code is in this line:> (*b)[*size_ptr++]= &a[i];

that increments 'size_ptr' as a pointer, not the value it points to.
Change it to (*b)[(*size_ptr)++] = &a[i];
You also don't check the return value of malloc. It could be NULL, in
which case you just return; the caller can check for the
successfulness of create_ptr_list(a, &b, c, &d); with if(b !=
NULL) ...

Also the design is flawed, mainly because this works only for arrays
of ints, and because 40 is hardcoded, how about you change this to
struct vector { size_t nmemb, size; void *elements; };
struct vector *remove_if(const struct vector *v, int (*remove)(void
*));

though I don't like the 'remove_if' name, I chose it because there's a
similar function in common lisp named REMOVE-IF.
.



Relevant Pages

  • Re: A taxonomy of types
    ... I am describing how to represent the representation (and, ... if the system follows static typing rules (such as in a compiler), ... so, the hardware sees pointers and pointer arithmetic, but the compiler ... "Besides the char types, up to three sizes of integer, declared short int, ...
    (comp.lang.misc)
  • Re: Malloc code
    ... int xxx; ... As for not using the void pointer, I will have to do some further testing ... I just needed some insight on passing arrays of pointers. ... struct MCB *r1; ...
    (microsoft.public.vc.language)
  • I want my segmentation fault!
    ... no occurrences of free and a lot of routines returning pointers to ... the pointer returned by the allocator (either directly or as a component ... int length_of_list; ...
    (comp.lang.c.moderated)
  • Re: Simple question, err... I think
    ... Your nodes contain no other indication of which pointers are valid, ... struct CountedObject ... int is_red; ... bool lament(char const s) ...
    (comp.programming)
  • misc, refocus: new possible lang idea, BSC
    ... object //prototypical object ... it may not be possible to assign between tagged-references and pointers, ... the other, if implemented, will be based on a class/instance system. ... int foo ...
    (comp.lang.misc)