From mathieu.ribatet at epfl.ch  Mon Feb  9 10:18:23 2009
From: mathieu.ribatet at epfl.ch (Mathieu Ribatet)
Date: Mon, 09 Feb 2009 10:18:23 +0100
Subject: [Rd] Strange behavior of C compiled program
In-Reply-To: <498FF1E0.2020103@u-paris10.fr>
References: <498F5EA4.3060307@u-paris10.fr> <498F6052.6070506@stats.uwo.ca>
	<498FF1E0.2020103@u-paris10.fr>
Message-ID: <1234171103.6503.8.camel@mathieu-laptop>

You might have a look at the "Writing R Extensions" manual - especially
valgrind and/or gdb.

By the way, your error is probably due to array size problem - i.e. tmp
is of size n and you call tmp[n+1] for example. Valgrind will detect in
automagically for you.

Best,
Mathieu

Le lundi 09 f?vrier 2009 ? 10:05 +0100, Christophe Genolini a ?crit :
> Thanks, that was a stupid mistake (I did not know that this is so 
> important).
> 
> So I still have a problem realy more complex and I do not know was is 
> wrong. I am running a .C procedure in a R loop.
> After 4, 5 or sometimes 6 call to the C procedure, Rgui crash (it closes 
> asking me if I want to send a report to Microsoft).
> Is there a debuger that can run the C code with some R in it ? And what 
> kind of mistake can provoque such a crash ?
> 
> Thanks
> Christophe
> 
> 
> So I thaught that I find t
> > On 08/02/2009 5:37 PM, Christophe Genolini wrote:
> >> Hi the list,
> >>
> >> I need to include some C code in R, but the behavior of the C code is 
> >> strange : Here is my code :
> >> --- 8< ---
> >>     Rprintf("\n XXXX mTraj=%f 
> >> mClus=%f",mTraj[i+nbId*c],mClustersCenter[j+nbClusters*c]);
> >>
> >>     Rprintf("\nDistA=%d Tmp=%d",dist,tmp);
> >>             tmp = mTraj[i+nbId* c] - mClustersCenter [j+nbClusters* c];
> >>
> >>     Rprintf("\nDistB=%d Tmp=%d",dist,tmp);
> >>             dist += (tmp * tmp);
> >>
> >>     Rprintf("\nDistC=%d Tmp=%d",dist,tmp);
> >> --- 8< ----
> >>
> >> Herer are the stranges results it gives :
> >>
> >> XXXX mTraj=1.000000 mClus=3.000000
> >> DistA=0 Tmp=0
> >> DistB=0 Tmp=0
> >> DistC=0 Tmp=1074790400
> >>
> >> I ask on a C chat, but no one can answer me.
> >> Any idea of what wrong ?
> >
> > You likely have the wrong types for the variables you're printing.  In 
> > C, the format has to match the type of the variable; if you use the 
> > wrong one, you get garbage.
> >
> > Duncan Murdoch
> >
> 
-- 
Institute of Mathematics
Ecole Polytechnique F?d?rale de Lausanne
STAT-IMA-FSB-EPFL, Station 8
CH-1015 Lausanne   Switzerland
http://stat.epfl.ch/
Tel: + 41 (0)21 693 7907



[Rd] Strange behavior of C compiled program
Mathieu Ribatet