0

My knowledge / experience of C is quite limited but I'm trying to create a node addon that uses a node buffer with a C call which expects the buffer to be of type 'unsigned char*' but from what I can see the node buffer Data method provides a 'char*' so the types are incompatible. E.g.

This is how it would be called using c:

int length = 100;
unsigned char buf[length];
int ret = ftdi_read_data(&ftdic, buf, length);

And from what I have read, to use a node buffer you do the following instead:

int length = 100;
node::Buffer *slowBuffer = node::Buffer::New(length);
int ret = ftdi_read_data(&ftdic, node::Buffer::Data(slowBuffer), length);

However this returns the following error when building:

error: invalid conversion from ‘char*’ to ‘unsigned char*’ [-fpermissive]
int ret = ftdi_read_data(&ftdic, node::Buffer::Data(slowBuffer), length);

Is it possible to create a node buffer of type unsigned chars, or achieve this in some other way?

Thanks

1 Answer 1

3

In your addon C code use a cast like this: (unsigned char*)node::Buffer::Data(slowBuffer). This is the usual fix for the specific error shown.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.