I forgot to put the folowing includes in my last post:

#include <R.h>
#include <Rdefines.h>



Thanks,


Ricardo



---------- Forwarded message ----------
From: Ricardo Luiz Andrade Abrantes <rabrantes82@gmail.com>
Date: Aug 30, 2005 1:37 PM
Subject: Re: [Rd] .Call and Segmentation Fault
To: Simon Urbanek <simon.urbanek@r-project.org>, r-devel@r-project.org

Hi Simon!
You are right!
Ok, here it is (a little resumed):

#include <stdio.h>
#include <math.h>
#include <time.h>
#include <sys/times.h>
#include "interface.h"

SEXP main() {

int gtype, inform, m, n, maxoutit, maxtotit, maxtotfc, outiter,
totcgcnt, totfcnt, totgcnt, totiter, iprint, ncomp, i;

double f,nalpsupn,epsfeas,epsopt,snorm;

int *wi;
int *equatn, *linear;

double *l, *lambda, *rho, *u, *wd1, *wd2, *wd3, *wd4, *wd5, *wd6, 
*wd7, *wd8, *wd9, *wd10, *wd11, *wd12, *wd13, *x;

FILE *fileOutput;
clock_t clock;
double time;
struct tms buffer;

/* SOME LINES TO SET UP PROBLEM DATA */

/* SOME LINES TO MEMORY ALLOCATION */

/* SOME LINES TO SET SOME ALGENCAN ARGUMENTS */

/* TRANSFORMS THE TYPE INT OF C IN THE TYPE LOGICAL OF FORTRAN 
* FOR THE ARRAYS equatn AND linear */

C2FLOGICALV(equatn, m);
C2FLOGICALV(linear, m);

clock = times(&buffer);

/* CALL OPTIMIZATION PACKAGE */

fortran_optimization_package (n, x, l, u, m, lambda, rho, equatn, linear, 
epsfeas,
epsopt, maxoutit, maxtotfc, maxtotit, iprint, ncomp, gtype,
f, snorm, nalpsupn, outiter, totiter, totfcnt, totgcnt,
totcgcnt, inform, wi, wd1, wd2, wd3, wd4, wd5, wd6, wd7,
wd8, wd9, wd10, wd11, wd12, wd13)

return R_NilValue
}

All the variables passed to fortran_optimization_package are allocated an 
initialized correctly, that's why I resumed those lines with a comment.


Thanks,


Ricardo




> You still didn't even supply your declaration of the function you're 
> calling, so there is not much we can help you with. Hopefully your
> function looks like this:
> 
> #include <R.h>
> #include <Rinternals.h>
> 
> SEXP foo() {
> 
> [... you code goes here..]
> 
> return R_NilValue;
> }
> 
> If you're constructing the returned object then you should consider
> posting the whole code, because you're likely making a mistake
> somewhere in that part.
> 
> Cheers,
> Simon
> 
>

	[[alternative HTML version deleted]]

