Skip to content

[Rcpp-devel] Using printf: Error in source("/tmp/printf.r") : /tmp/printf.r:8:11: unexpected input

3 messages · Paul Menzel, Romain Francois

#
Dear Rcpp folks,


could you please give me a hint on how to use `printf`.

        library(inline)
        inc <- "
        #include <stdio.h>
        "
        
        drucken <-cxxfunction(includes=inc, plugin="Rcpp", body="
          unsigned int length = 1;
          printf("%u\\n", length);
        
          return wrap(length);
        ")

throws the following error, when I try to source it.

        > source("/tmp/printf.r")
        Error in source("/tmp/printf.r") : /tmp/printf.r:8:11: unexpected input
        7:   unsigned int length = 1;
        8:   printf("%u\\n", length);

Removing the `printf` statement gets rid of the error. I tested the
standalone example and `gcc` does not complain.

        /* printf example */
        #include <stdio.h>
        
        int main()
        {
          unsigned int length = 1;
          printf("%u \n", length);
        
          return length;
        }

Probably my mistake is a simple one because
works and `printf` statements are used in there. (I had to install
`libgsl0-dev` to get the headers.)


Thanks,

Paul
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.c
Type: text/x-csrc
Size: 138 bytes
Desc: not available
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20111118/30deda5b/attachment.c>
-------------- next part --------------
library(inline)
inc <- "
#include <stdio.h>
"

rw <-cxxfunction(includes=inc, plugin="Rcpp", body="
  unsigned int length = 1;
  printf("%u\\n", length);

  return wrap(length);
")
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20111118/30deda5b/attachment.pgp>
#
This has nothing to do with printf, this is simply because you use 
double quotes 'inside' double quotes, replace the outer quotes by single 
quotes and you should be fine.

Please also note that Rprintf is preferred, because it will work on all 
platforms or user interfaces.

Hope this helps,

Romain


Le 18/11/11 20:32, Paul Menzel a ?crit :

  
    
#
Dear Romain,


Am Freitag, den 18.11.2011, 20:39 +0100 schrieb Romain Fran?ois:
that easy, huh? ;-)
Interesting. Thank you.
A lot!


Thanks a million,

Paul
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20111118/5a9d3346/attachment.pgp>