Click here to Skip to main content
15,887,027 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Problem with Threads Pin
yamini26-Jun-01 22:51
yamini26-Jun-01 22:51 
GeneralRe: Problem with Threads Pin
Bob Groves27-Jun-01 1:37
Bob Groves27-Jun-01 1:37 
GeneralRe: Problem with Threads Pin
Joe Moldovan27-Jun-01 8:32
Joe Moldovan27-Jun-01 8:32 
GeneralView in a Dialog window Pin
26-Jun-01 21:19
suss26-Jun-01 21:19 
GeneralRe: View in a Dialog window Pin
Michael P Butler26-Jun-01 22:29
Michael P Butler26-Jun-01 22:29 
GeneralRe: View in a Dialog window Pin
27-Jun-01 21:47
suss27-Jun-01 21:47 
GeneralRe: View in a Dialog window Pin
Michael P Butler27-Jun-01 22:23
Michael P Butler27-Jun-01 22:23 
GeneralAh, pointers... Pin
Shankar Chandra Bose26-Jun-01 20:05
Shankar Chandra Bose26-Jun-01 20:05 
Chaps and fellow geeks,

I have a pointer to an array of 10 chars (note that this is different from an array of ten chars, which allocates 10 bytes, the former allocates 4 bytes). This means, whenever I increment the pointer, I can skip by 10 bytes. I then proceed to allocate 100 bytes of storage (as I want to treat it as a 10 by 10 array). Trouble is (well, not really trouble), when I use new to allocate 100 bytes for the pointer I need to typecast the pointer returned by the new operator to the type of "pointer to an array". Towards this end, I have typedefed CHARTENARRAY as a pointer to an array of 10 bytes. I then typecast the return value of new like so: pArray = (CHARTENARRAY) new char[100];

I would like to know if there is a way of doing this *without* the typedef. How would I typecast it? In general, what would be the cast for a pointer to an array of x bytes that is returned, by the new operator when it is used to allocate x bytes?

To make things clear, here is the source (with lots of comments), you can compile it and run it if you'd like to experiment:



typedef char (*CHARTENARRAY)[10]; // typedefines CHARTENARRAY to be a pointer to an array of 10 b
CHARTENARRAY pArray = NULL;

pArray = (CHARTENARRAY) new char[100]; // need to do this WITHOUT the (CHARTENARRAY) typedef.

for(int i = 0; i < 10; ++i)
{
strcpy(*pArray, "HELLO!"); // Fill in 10 "HELLO!" strings in 10 slots
++pArray; // increment by 10 bytes (scalar)
}

pArray -= 10; // Go to array start (will decrement by 100 bytes, since scalar is 10)

for(i = 0; i < 10; ++i) // Display routine
{
puts(*pArray);
++pArray; // Go to next string
}

pArray -= 10; // Go to array start
delete [] pArray; // Free
GeneralRe: Ah, pointers... Pin
Michael Dunn26-Jun-01 21:28
sitebuilderMichael Dunn26-Jun-01 21:28 
GeneralRe: Ah, pointers... Pin
Shankar Chandra Bose26-Jun-01 21:48
Shankar Chandra Bose26-Jun-01 21:48 
QuestionWhy?? Pin
26-Jun-01 18:23
suss26-Jun-01 18:23 
AnswerRe: Why?? Pin
Frank Liao26-Jun-01 19:00
Frank Liao26-Jun-01 19:00 
GeneralRe: Why?? Pin
26-Jun-01 20:14
suss26-Jun-01 20:14 
GeneralRe: Why?? Pin
Michael Dunn26-Jun-01 21:32
sitebuilderMichael Dunn26-Jun-01 21:32 
GeneralRe: Why?? Pin
Frank Liao27-Jun-01 3:42
Frank Liao27-Jun-01 3:42 
AnswerRe: Why?? Pin
Rejeesh27-Jun-01 4:11
Rejeesh27-Jun-01 4:11 
QuestionHow Can convert BSTR to LPCSTR OR vice versa! Pin
bluestn26-Jun-01 17:10
bluestn26-Jun-01 17:10 
AnswerRe: How Can convert BSTR to LPCSTR OR vice versa! Pin
Christian Graus26-Jun-01 17:14
protectorChristian Graus26-Jun-01 17:14 
GeneralRe: How Can convert BSTR to LPCSTR OR vice versa! Pin
Venkat Raghavan26-Jun-01 17:28
Venkat Raghavan26-Jun-01 17:28 
AnswerRe: How Can convert BSTR to LPCSTR OR vice versa! Pin
Erik Thompson26-Jun-01 18:29
sitebuilderErik Thompson26-Jun-01 18:29 
GeneralRich Text (RichEdit) Tab Setting Pin
Steven Armstrong26-Jun-01 17:00
Steven Armstrong26-Jun-01 17:00 
GeneralCString to Integer Pin
PJ Arends26-Jun-01 16:56
professionalPJ Arends26-Jun-01 16:56 
GeneralRe: CString to Integer Pin
Michael Dunn26-Jun-01 18:04
sitebuilderMichael Dunn26-Jun-01 18:04 
GeneralRe: CString to Integer Pin
27-Jun-01 1:49
suss27-Jun-01 1:49 
GeneralUsing CDoc's data for a new document in MDI Pin
mr200326-Jun-01 16:05
mr200326-Jun-01 16:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.