Archived

This topic is now archived and is closed to further replies.

Pfhorseti

Help - delaying declaration of char array to compile time

Recommended Posts

Hi, I have a class, where in it''s header declares a char pointer: char *myPointer; In it''s constructor I want to actually allocate the char array using user''s provided info (array size). So in it''s constructor (actually an -init method, written in Obj-C), I do: char allocatedTempBuffer[[[[NSUserDefaults standardUserDefaults] objectForKey:@"maximumPacketSize"] intValue]]; tempBuffer = allocatedTempBuffer; Above code is logically the same as: char allocatedTempBuffer[256]; tempBuffer = allocatedTempBuffer; I thought I did this right, but later on when I call memcpy(), my compiler gives me an error (STServer.m:238: warning: passing arg 1 of `memcpy'' makes pointer from integer without a cast). Here''s the line: memcpy([[connectedClients objectForKey:[NSNumber numberWithInt:newSocketID]] workBuffer][totalBytesReceived], tempBuffer, bytesReceived); Which is again the same as: memcpy(workBuffer[startingPoint], tempBuffer, bytesToCopy); Why is this an incorrect use of my pointer variable? This may be a basic question. I am kind of slow with pointers. Thank you for the help! -Yuki

Share this post


Link to post
Share on other sites