Skip to content
Prev 138625 / 398503 Next

R_alloc with structures with "flexible array members"

Dear Jeff,

Thanks for the suggestion. However, something is still not working.
This is a simple example:

***************************  start C ************
#include <R.h>

struct Sequence {
  int len;
  unsigned int state_count[];
};


int main(void) {

  struct Sequence *A;
  int n = 4;

  // First line segfaults. Second doesn't
    A = (struct Sequence *) R_alloc(1,  sizeof(struct Sequence) + n *
sizeof(unsigned int));
  //  A = malloc(sizeof(struct Sequence) + n * sizeof(unsigned int));

  return(0);
}

***********  end C  **********


I then do
gcc -std=gnu99 -Wall -I/usr/share/R/include -I/usr/share/R/include
-L/usr/lib/R/lib -lR ex7.c

and the ./a.out segfaults when I use R_alloc (not with malloc).


Best,

R.

On Wed, Mar 5, 2008 at 5:23 PM, Jeffrey Horner
<jeff.horner at vanderbilt.edu> wrote: