Click here to Skip to main content
15,885,996 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Classic question: dynamic 2D arrays in standard C Pin
bouli25-Feb-06 2:54
bouli25-Feb-06 2:54 
GeneralRe: Classic question: dynamic 2D arrays in standard C Pin
bouli25-Feb-06 5:06
bouli25-Feb-06 5:06 
AnswerRe: Classic question: dynamic 2D arrays in standard C Pin
David Crow25-Feb-06 3:58
David Crow25-Feb-06 3:58 
GeneralRe: Classic question: dynamic 2D arrays in standard C Pin
bouli25-Feb-06 5:06
bouli25-Feb-06 5:06 
Questiona question that did not get any true answer :(( Pin
Hamed Musavi25-Feb-06 0:16
Hamed Musavi25-Feb-06 0:16 
AnswerRe: a question that did not get any true answer :(( Pin
Stephen Hewitt25-Feb-06 0:29
Stephen Hewitt25-Feb-06 0:29 
GeneralRe: a question that did not get any true answer :(( Pin
Hamed Musavi25-Feb-06 0:42
Hamed Musavi25-Feb-06 0:42 
GeneralRe: a question that did not get any true answer :(( Pin
Stephen Hewitt25-Feb-06 0:56
Stephen Hewitt25-Feb-06 0:56 
The general pattern to this kind of stuff is this:
// Call read.
read((void*)&st); // This cast throws away type information.
 
void read(void* pData)
{
     x* pX = (x*)pData; // This cast "recovers" the type info.
     // Do stuff here...
}


Naturally if we have code like this we're in real trouble:
int data;
read((void*)&data);


The reason we get in trouble is that, since we throw away the type information with the void* cast we're forced to cast back in the read function and the compiler has no way of checking the validity of the cast. In general casts represent a design flaw, which is one of the reasons why C++ introduced the static_cast, const_cast and reinterpret_cast keywords - casts are ugly and so should look ugly and be easy to find. There are times when casting is necessary but this should only be at the low-level portions of an application and the actual casts should be hidden behind type safe interfaces.


Steve
GeneralRe: a question that did not get any true answer :(( Pin
Hamed Musavi25-Feb-06 1:07
Hamed Musavi25-Feb-06 1:07 
GeneralRe: a question that did not get any true answer :(( Pin
Stephen Hewitt25-Feb-06 1:19
Stephen Hewitt25-Feb-06 1:19 
GeneralRe: a question that did not get any true answer :(( Pin
Hamed Musavi25-Feb-06 1:29
Hamed Musavi25-Feb-06 1:29 
GeneralRe: a question that did not get any true answer :(( Pin
Stephen Hewitt25-Feb-06 2:37
Stephen Hewitt25-Feb-06 2:37 
GeneralRe: a question that did not get any true answer :(( Pin
Hamed Musavi25-Feb-06 20:15
Hamed Musavi25-Feb-06 20:15 
QuestionRe: a question that did not get any true answer :(( Pin
Hamed Musavi25-Feb-06 1:09
Hamed Musavi25-Feb-06 1:09 
AnswerRe: a question that did not get any true answer :(( Pin
Stephen Hewitt25-Feb-06 1:12
Stephen Hewitt25-Feb-06 1:12 
GeneralRe: a question that did not get any true answer :(( Pin
Hamed Musavi25-Feb-06 1:20
Hamed Musavi25-Feb-06 1:20 
GeneralRe: a question that did not get any true answer :(( Pin
toxcct25-Feb-06 9:00
toxcct25-Feb-06 9:00 
GeneralRe: a question that did not get any true answer :(( Pin
Hamed Musavi25-Feb-06 20:24
Hamed Musavi25-Feb-06 20:24 
GeneralRe: a question that did not get any true answer :(( Pin
BadKarma25-Feb-06 23:11
BadKarma25-Feb-06 23:11 
GeneralRe: a question that did not get any true answer :(( Pin
Hamed Musavi26-Feb-06 2:38
Hamed Musavi26-Feb-06 2:38 
NewsI thought about a soloution. Pin
Hamed Musavi25-Feb-06 1:44
Hamed Musavi25-Feb-06 1:44 
QuestionColor picker extension Pin
Hans Dietrich25-Feb-06 0:05
mentorHans Dietrich25-Feb-06 0:05 
AnswerRe: Color picker extension Pin
Blake Miller27-Feb-06 6:05
Blake Miller27-Feb-06 6:05 
QuestionSocket Communication Pin
kk.tvm24-Feb-06 21:24
kk.tvm24-Feb-06 21:24 
AnswerRe: Socket Communication Pin
Naveen24-Feb-06 22:19
Naveen24-Feb-06 22:19 

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.