Click here to Skip to main content
14,661,630 members
Home » Discussions » C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Accessing HDD drive Pin
JudyL_MD19-Apr-20 4:31
MemberJudyL_MD19-Apr-20 4:31 
Questionvoid type Pin
CalinNegru(fearless_)10-Apr-20 22:20
MemberCalinNegru(fearless_)10-Apr-20 22:20 
AnswerRe: void type Pin
Richard MacCutchan10-Apr-20 22:25
mveRichard MacCutchan10-Apr-20 22:25 
GeneralRe: void type Pin
CalinNegru(fearless_)10-Apr-20 22:44
MemberCalinNegru(fearless_)10-Apr-20 22:44 
GeneralRe: void type Pin
Richard MacCutchan10-Apr-20 23:18
mveRichard MacCutchan10-Apr-20 23:18 
GeneralRe: void type Pin
Member 798912211-Apr-20 1:22
MemberMember 798912211-Apr-20 1:22 
GeneralRe: void type Pin
CalinNegru(fearless_)11-Apr-20 10:25
MemberCalinNegru(fearless_)11-Apr-20 10:25 
GeneralRe: void type Pin
Member 798912211-Apr-20 11:36
MemberMember 798912211-Apr-20 11:36 
What else would it be? In C, a pointer is an address, nothing more.

In other languages, such as C#, a reference is a the memory address of an object, comparable to a struct, containing not only the values of the members, but also a pointer to another struct, the class object, with pointers to the various member functions. Also in C#, an array reference is a pointer to a "struct" providing the index limit of the array. If you go back to good old Pascal. any string was headed by its length, any array by fields indicating its upper and lower index limits.

Not so with C. For reasons of space efficiency, space couldn't be wasted on such.

If you are programming in C++, a pointer to a class instance is similar: It points to a struct augmented by a reference to a class object (which may in turn have a pointer to a superclass object, with a pointer to an even superer object, and so on up to the very object class with all the attributes common to all objects. When you call a method for some bottom layer object, a search through this hierarchy is made to find method pointer. For virtual methods defined at a high/intermediate level, a pointer may be found at a lower level that where the virtual function is defined, and different (sub)class objects may provide different pointers to their respective implementations of the virtual functions. Static members at various levels of subclassing may be located in the class objects, common to all subclasses.

If you implement an array in C++ as class with an array member, you may of course store the maximum index as another class member and route all accesses through a member function verifying that no access violates the index limit. Roughly speaking, you could say that that's what happening in C# (or good old Pascal). But both for "performance" reasons (don't make any hard tests! You'd be disappointed!) and for backwards compatibility with classical C, an array name is nothing but a pointer (where you don't have to write the *), and a pointer, whether an array name or an explicit one (requiring a * for dereferencing) is nothing but a memory address.

Oldtimers remember the BASIC functions PEEK(address) and POKE(address) for reading/writing any value at 'address'. I am not sure that C compilers of today allow you to read/write the "array element" at 0[address]. In my student days they did. I certainly hope that they do not today... But then again, there is nothing in the C syntax rules prohibiting it, so why shouldn't you use it?

GeneralRe: void type Pin
Richard MacCutchan11-Apr-20 23:40
mveRichard MacCutchan11-Apr-20 23:40 
GeneralRe: void type Pin
Member 798912211-Apr-20 12:01
MemberMember 798912211-Apr-20 12:01 
GeneralRe: void type Pin
Greg Utas12-Apr-20 0:20
professionalGreg Utas12-Apr-20 0:20 
GeneralRe: void type Pin
leon de boer11-Apr-20 21:51
Memberleon de boer11-Apr-20 21:51 
GeneralRe: void type Pin
CalinNegru(fearless_)11-Apr-20 21:47
MemberCalinNegru(fearless_)11-Apr-20 21:47 
QuestionHow do I add listboxes to a back buffer and use that? Pin
PotatoSoup6-Apr-20 5:57
MemberPotatoSoup6-Apr-20 5:57 
AnswerRe: How do I add listboxes to a back buffer and use that? Pin
Richard MacCutchan6-Apr-20 6:21
mveRichard MacCutchan6-Apr-20 6:21 
GeneralRe: How do I add listboxes to a back buffer and use that? Pin
PotatoSoup6-Apr-20 6:46
MemberPotatoSoup6-Apr-20 6:46 
GeneralRe: How do I add listboxes to a back buffer and use that? Pin
Richard MacCutchan6-Apr-20 7:04
mveRichard MacCutchan6-Apr-20 7:04 
GeneralRe: How do I add listboxes to a back buffer and use that? Pin
PotatoSoup6-Apr-20 7:26
MemberPotatoSoup6-Apr-20 7:26 
GeneralRe: How do I add listboxes to a back buffer and use that? Pin
Victor Nijegorodov6-Apr-20 8:24
MemberVictor Nijegorodov6-Apr-20 8:24 
GeneralRe: How do I add listboxes to a back buffer and use that? Pin
PotatoSoup6-Apr-20 8:43
MemberPotatoSoup6-Apr-20 8:43 
GeneralRe: How do I add listboxes to a back buffer and use that? Pin
Victor Nijegorodov6-Apr-20 8:49
MemberVictor Nijegorodov6-Apr-20 8:49 
GeneralRe: How do I add listboxes to a back buffer and use that? Pin
PotatoSoup6-Apr-20 11:07
MemberPotatoSoup6-Apr-20 11:07 
GeneralRe: How do I add listboxes to a back buffer and use that? Pin
leon de boer6-Apr-20 21:06
Memberleon de boer6-Apr-20 21:06 
SuggestionRe: How do I add listboxes to a back buffer and use that? Pin
David Crow6-Apr-20 8:59
MemberDavid Crow6-Apr-20 8:59 
GeneralRe: How do I add listboxes to a back buffer and use that? Pin
PotatoSoup6-Apr-20 11:31
MemberPotatoSoup6-Apr-20 11:31 

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.