From murdoch.duncan at gmail.com  Thu Jun  9 16:54:28 2011
From: murdoch.duncan at gmail.com (Duncan Murdoch)
Date: Thu, 09 Jun 2011 10:54:28 -0400
Subject: [Rd] "warning: assignment discards qualifiers from pointer
 target type"
In-Reply-To: <20110609132817.GA5438@siouxsie>
References: <20110607130854.GA4510@siouxsie> <4DEE3786.5000800@gmail.com>
	<alpine.LFD.2.02.1106071606010.26985@gannet.stats.ox.ac.uk>
	<20110608160839.GA11746@siouxsie>
	<B68723F7-F66B-40FD-AE38-0A88C0C51B82@r-project.org>
	<20110609001731.GA3565@siouxsie> <20110609003209.GA4839@siouxsie>
	<86C9E656-BCF4-48C8-8016-877DFAA0D158@r-project.org>
	<20110609112715.GA3855@siouxsie> <4DF0B1D8.4080605@gmail.com>
	<20110609132817.GA5438@siouxsie>
Message-ID: <4DF0DEA4.9000602@gmail.com>

On 09/06/2011 9:28 AM, oliver wrote:
> On Thu, Jun 09, 2011 at 07:43:20AM -0400, Duncan Murdoch wrote:
> >  On 11-06-09 7:27 AM, oliver wrote:
> >  >On Wed, Jun 08, 2011 at 08:35:34PM -0400, Simon Urbanek wrote:
> >  >>
> >  >>On Jun 8, 2011, at 8:32 PM, oliver wrote:
> >  >>
> >  >>>On Thu, Jun 09, 2011 at 02:17:31AM +0200, oliver wrote:
> >  >>>[...]
> >  >>>>OK, I looked at this now.
> >  >>>>
> >  >>>>LENGTH() checks the length of the vector.
> >  >>>>
> >  >>>>Good to know this.
> >  >>>>
> >  >>>>So the problem of a vector of length 0 can be with any arguments of type SEXP,
> >  >>>>hence I will need to check ANY arg on it's length.
> >  >>>>
> >  >>>>This is vital to stability under any situation.
> >  >>>>
> >  >>>>Thanks for this valuable hint!
> >  >>>>
> >  >>>>I will add checks for all my SEXP-args.
> >  >>>[...]
> >  >>>
> >  >>>Hey, LENGTH() does not work with String-vectors! :(
> >  >>>
> >  >>
> >  >>Of course it does ...
> >  >>
> >  >>
> >  >
> >  >It does not so on my R 2.10.1 installation.
> >  >
> >  >
> >  >In the R-Shell I get:
> >  >
> >  >    ==============================
> >  >    >   length(c())
> >  >    [1] 0
> >  >    >
> >  >    ==============================
> >  >
> >  >So c() is vec of length 0.
> >  >
> >  >When I feed my readjpeg() with c() as filename arg,
> >  >
> >  >testing with:
> >  >====================================================
> >  >    if( LENGTH( filename_sexp )<   1 )
> >  >    {
> >  >      error("LENGTH( filename_sexp )<   1");
> >  >      //error("filename can't be vector of length 0");
> >  >    }
> >  >    else
> >  >    {
> >  >      error("LENGTH( filename_sexp ) is not<   1");
> >  >    }
> >  >====================================================
> >  >
> >  >
> >  >I got:
> >  >    Error in readjpeg(filename = c()) : LENGTH( filename_sexp ) is not<   1
> >  >
> >  >
> >  >You can explain why?
> >
> >  c() doesn't create a STRSXP, it is NULL, which is a NILSXP.
> >  LENGTH() doesn't work on that object.  (I'd recommend using length()
> >  rather than LENGTH(); it's a function, not a macro, and it does give
> >  the expected answer.)
> [...]
>
> Interestingly, c() as value for an integer value
> can be testes correctly with LENGTH().

Presumably you converted it to an INTSXP.  c() is NULL.

> So the question arises: is c() always creating NILSXP,
> or is it NILSXP only for STRSXP, and 0 otherwise?

That question makes no sense at all.

Duncan Murdoch

> NILSXP, as it might be close to a NULL might be interpreted as 0
> length by LENGTH...
>
> Nevertheless it's a littlebid confusing for people who don't know the
> internals of R.
>
> Will try length() soon.
>
> Ciao,
>     Oliver
>
>
>
> P.S.: To be picky: NOT knowing the internals and nevertheless using the available
>        functions/macros is called encapsulation in OO or the difference between
>        interface and implementation... which is good style of programming.
>



[Rd] "warning: assignment discards qualifiers from pointer target type"
Duncan Murdoch