no matching function for call to 'fopen' - fopen

I want to call fopen within my cpp function, however, Rcpp always complains about "no matching function for call to 'fopen'".
So duplicated exactly the some code from https://github.com/hadley/xml2/blob/9362d379e126a86091af8698a8987c51b5b230fe/src/xml2_doc.cpp and still have the same error.
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
void doc_write(std::string path){
FILE* f = fopen(path.c_str(), 'r');
fclose(f);
}
and the error is:
testc.cpp:6:36: error: invalid conversion from 'char' to 'const char*' [-fpermissive]
Can someone point some hints on me?

The error message tells you everything you need to know - you're trying to pass a char parameter where a const char * is required.
replace 'r' with "r" that should fix it.

Related

pybind11, convert std::vector to py::list

According to the pybind11 documentation https://pybind11.readthedocs.io/en/stable/advanced/cast/stl.html:
When including the additional header file pybind11/stl.h, conversions between std::vector<>/std::list<>/std::array<>, std::set<>/std::unordered_set<>, and std::map<>/std::unordered_map<> and the Python list, set and dict data structures are automatically enabled.
However, I cannot for the life of me get this to work. I suppose I am misunderstanding something, so I hope someone can clear it up for me.
Here is what I expected to work:
// Test
std::vector<double> test_vec{1,2,3,4,5};
py::list test_list = test_vec;
py::list test_list2(test_vec);
py::list test_list3 = py::cast<py::list>(test_vec);
And here are the errors:
error: conversion from ‘std::vector<double>’ to non-scalar type ‘pybind11::list’ requested
py::list test_list = test_vec;
error: no matching function for call to ‘pybind11::list::list(std::vector<double>&)’
py::list test_list2(test_vec);
error: no matching function for call to ‘cast(std::vector<double>&)’
py::list test_list3 = py::cast<py::list>(test_vec)
The docs say to look in tests/test_stl.cpp for examples of how this should work, however I'm afraid that I am having trouble deciphering what is happening in that file.
The conversion happens automatically for function arguments and return values that you create bindings for if you include pybind11/stl.h. You can also do it explicitly in C++ code like this:
#include <pybind11/stl.h>
// [...]
std::vector<double> test_vec{1, 2, 3, 4, 5};
py::list test_list3 = py::cast(test_vec);
Please bear in mind that this creates a copy, though.
For a different approach please refer to making-opaque-types and binding-stl-containers.

Updateing code to swift 4 results in an error message

I wan to update this code to swift 4:
rc = select(socket_fd + 1, readfd, writefd, NULL, &timeout);
return rc;
}
But I get two errors:
Declaration of 'select' must be imported from module 'Darwin.POSIX.sys.time' before it is required
Implicit declaration of function 'select' is invalid in C99
How can I can fix this?
Add this near the top of your file:
#include <sys/time.h>

Extern function in interface

I am trying to declare a extern function in an interface and implementing it in a separate file in an effort to make our testharness generic.
What i want is something like this:
in_check.sv
interface in_check;
extern function bit fu_check(int num, logic state);
endinterface
in_impl.sv
interface in_impl(in_check uin_check);
function bit uin_check.fu_check(int num, logic state);
if(state) return num;
else return 0;
endfunction
endinterface
But Questasim gives me this error message:
** Error: (vsim-3787) in_impl.sv: Exported function 'uin_check.fu_check' arguments don't match those of export/extern task in interface 'in_check'.
This indicated that it should at least be possible with implicit declaration, but implicitly defined functions (i.e. extern function fu_check) gives this error message:
** Error: (vlog-13069) in_check.sv(20): near "fu_check": syntax error, unexpected IDENTIFIER.
Tasks work perfectly, and I can live with having to use an output argument. However, I would much prefer to be able to give a return value.
How can I make this work?
Bonus question: The LRM seems a bit light in info on this, is the implementation tool specific?

Matlab calling superclass abstract constructor syntax seems strange

I am trying to call a superclass constructor from the inheriting class.
The official syntax in matlab documentation is:
obj = obj#SuperClass(ArgumentList);
However the editor seems to warn that:
the variable `obj` might be used before it is defined.
Moreover, if I try to run the code I get an error "The left operand of "#" must be the method name."
What could be wrong?
I found out that this is a result of a typo of the sub-class constructor function name. Minimal reconstruction of the problem appears below:
classdef SuperDemo < handle
methods
function obj = SuperDemo(opt)
disp(['in super ', opt])
end
end
end
classdef SubDemo < SuperDemo
methods
function obj = SubDemoo(opt) % NOTICE THE TYPO SubDemoo
disp(['in sub ', opt])
obj = obj#SuperDemo(opt);
end
end
end
If you call s = SubDemo('hello') you will get the error:
Error using SubDemo Error: File: SubDemo.m Line: 5 Column: 19 "#"
Within a method, a superclass method of the same name is called by
saying method#superclass. The left operand of "#" must be the method
name.
This error is misleading as the left operand is obj and not SubDemo.
The error message should have indicated that the construction function name SubDemoo is not the same as the class name SubDemo.

error with callback function

I am trying to register a keyboard callback function to a 3D viewer using the Point Cloud Library API.
Todo this I do:
viewer->registerKeyboardCallback(&(RailExtraction::keyboard_callback), (void*)(&gt_data));
But I get the following error message:
note: no known conversion for argument 1 from 'void (RailExtraction< pcl::PointXYZI >::*)
(const pcl::visualization::KeyboardEvent&, void*)' to 'void (*)(const pcl::visualization::KeyboardEvent&, void*)'
I am trying to understand the error message. I understand what void and void * mean but what does void(*)(...) or void(RailExtraction< pcl::PointXYZI >::*>(...) mean ??
I figured out the problem I am using the wrong version of registerKeyBoardCallBack. I am currently trying to use this signature:
registerKeyboardCallback (void (*callback) (const pcl::visualization::KeyboardEvent&, void*), void* cookie = NULL)
But I should be using this signature:
registerKeyboardCallback (void (T::*callback) (const pcl::visualization::KeyboardEvent&, void*), T& instance, void* cookie = NULL)
This is because my keyboard_callback function is part of a class and therefore I need to specify the instance of the class so that the compiler can figure out which instance the keyboard_callback function to use. Therefore my new call to registerKeyboardCallBack looks like this:
viewer->registerKeyboardCallback(&RailExtraction::keyboard_callback, *this, (void*)&gt_data);