Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot initialize a variable of type 'PTExampleTextFrame *' (aka '_PTExampleTextFrame *') with an rvalue of type 'void *' #47

Open
anonym24 opened this issue Apr 13, 2018 · 1 comment

Comments

@anonym24
Copy link

anonym24 commented Apr 13, 2018

Example for iOS works ok, but when I'm trying to use libs in my own project (swift version with objective-c++ .mm classes bridges) I get next error:

Cannot initialize a variable of type 'PTExampleTextFrame *' (aka '_PTExampleTextFrame *') with an rvalue of type 'void *'

in this function (Peertalk Example) PTExampleProtocol.h

also this header file for Mac target/project, so does why iOS target/project reference to it?

static dispatch_data_t PTExampleTextDispatchDataWithString(NSString *message) {
  // Use a custom struct
  const char *utf8text = [message cStringUsingEncoding:NSUTF8StringEncoding];
  size_t length = strlen(utf8text);
  //CFAllocatorAllocate(nil, 1 + length, 0);
  PTExampleTextFrame *textFrame = CFAllocatorAllocate(nil, sizeof(PTExampleTextFrame) + length, 0);
  memcpy(textFrame->utf8text, utf8text, length); // Copy bytes to utf8text array
  textFrame->length = htonl(length); // Convert integer to network byte order
  
  // Wrap the textFrame in a dispatch data object
  return dispatch_data_create((const void*)textFrame, sizeof(PTExampleTextFrame)+length, nil, ^{
    CFAllocatorDeallocate(nil, textFrame);
  });

screenshot at apr 13 16-18-13

@FlorianSchmittDE
Copy link

CFAllocatorAllocate returns a value of type void, which can't be assigned to PTExampleTextFrame as its a struct (thats exactly what the error says)

As a quick'n'dirty solution just cast the returned value of the CFAllocatorAllocate as type (struct _PTExampleTextFrame)

So replace this:

PTExampleTextFrame *textFrame = CFAllocatorAllocate(nil, sizeof(PTExampleTextFrame) + length, 0);
  memcpy(textFrame->utf8text, utf8text, length);

with

PTExampleTextFrame *textFrame = (struct _PTExampleTextFrame*) CFAllocatorAllocate(NULL, sizeof(PTExampleTextFrame) + length, 0);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants