I want to thank all respondents for the list of books and websites. It will 
take me a few days to go through each email and recommendation.


To others who were concerned about the use of memset(), I do use memset, when 
there are no linked lists.  My structures that I zap rarely if  ever contain 
pointers to linked lists.  Typically in my code  I do a  xx=alloc(sizeof struct 
yyy)  followed by a memset, or I do xx  = calloc(sizeof struct yyy) because I 
want hex zeros everywhere when the xx is initialized. 


I tend to keep integers or short strings or string pointers when allocating a 
new structure. The null pointer is what I do want when there is a new 
allocation.  


I have too many years of assembly, Pascal and C, so that I am after easing  the 
transition to thinking and working with objects, mainly in a gui environment .  

For example in C, we tend to use individual #include files. whereas in CPP, 
because of classes I noted that the tendency is to do #include within 
#include's, due to class definitions.  I think that in general #includes within 
#includes is wrong.  
I should bring this question up on a programming website, but posted it here to 
explain what irks me and blocks me from accepting OO.

I am practicing with QT and the SDK. 

------------------


Regards

 Leslie

Mr. Leslie Satenstein
50 years in IT and going strong.
Yesterday was a good day, today is a better day,
and tomorrow will be even better.
 
mailto:[email protected]
alternative: [email protected] 
www.itbms.biz  




>________________________________
> From: Andy Pintar <[email protected]>
>To: Montreal Linux Users Group <[email protected]> 
>Sent: Tuesday, March 20, 2012 10:56 PM
>Subject: Re: [MLUG] Off Topic C++ course
> 
>On Tue, 20 Mar 2012, Patricia Campbell wrote:
>
>> >From your email you are thinking in non OOP terms.  If you want to use C++
>> you will have to switch your thinking a bit.  I recommend Deitel & Deitel
>> C++ any version > 5 will probably do for
>> conceptshttp://www.amazon.com/How-Program-8th-Paul-Deitel/dp/0132662361
>
>Great advice as always, Patricia.  I'd recommend Bruce Eckel's "Thinking in 
>C++" first and second volumes.
>http://mindview.net/Books/TICPP/ThinkingInCPP2e.html
>
>They're free, easy to read/follow, plenty of bite-sized examples, and I think 
>much more intuitively organized than, say, the O'Reilly nutshell/programming 
>books.
>
>>  If I can do sizeof(structure) to get its size in memory. Can I do the
>> same of a class.  sizeof(class) ?
>
>Structs and classes are the same, the only difference is public vs private by 
>default.  But structs in C++ aren't the same as structs in C!  Read a 
>thorough, detailed intro book and you'll see why thinking of C++ as an 
>extension to C is a bad idea.  It is probably one of the greatest disservices 
>to C programmers who want to learn C++, who think 'oh it's just some language 
>extensions.'  But sizeof works as expected.
>
>> One other question.  In C, I can do a memset(structure 
>address, 0, > sizeof(structure)), and that will zap the structure.
>
>Don't do that!  Even in C!  Sure, for a struct that contains a pair of floats 
>that's fine (some kind of point(x,y) struct).  But what about a linked list 
>implementation?  If you have a linked list that cointains a {pointer to value, 
>pointer to next item}, and you zap the head of your list, you didn't clean up 
>the value or the other elements, just 2 pointers.  What, you had thousands of 
>items in that list?  And no way to accesss them?  Memory leak!  Same holds 
>true in c++, that's why you have a destructor that you write which goes 
>through each element explicitly.
>
>But more importantly, why are you memsetting it to zero (in C)?  That makes no 
>sense at all.. sure you could do it, but why not just set the struct's 
>elements to zero?  Or if you want to 'delete' it, just let it fall out of 
>scope...  Please share the point of that 'zap' and I or someone else can 
>better explain an equivalent idea in C++.
>
>> Can I put the structure within a class and do the same?  I think I am
>> not able to do the memset(?class,0 sizeof(class))
>> clearout because of private variables.
>
>Structs=classes.  Sort of.  But don't go memsetting like that.  You're going 
>to end up with really broken code really quickly.  If you think you're going 
>to save some cycles, you're wrong.  Create a method, say 'clear()', that sets 
>internal class/struct state to "zero", or somesuch.
>
>
>Check out Eckel's books.  Don't go into it thinking you can use any of your C 
>knowledge (other than where to put a ';' or scope blocks inside '{' '}', 
>etc).  It's a totally different approach that's designed to make it easier to 
>represent abstract concepts more efficiently than in procedural C.  That 
>doesn't mean the code is faster, although it often is for complex projects 
>because it is more concisely defined than it could be in C.
>
>Blah blah blah....
>Sorry for the long post, I hope you find it helpful.
>_______________________________________________
>mlug mailing list
>[email protected]
>https://listes.koumbit.net/cgi-bin/mailman/listinfo/mlug-listserv.mlug.ca
>
>
>
_______________________________________________
mlug mailing list
[email protected]
https://listes.koumbit.net/cgi-bin/mailman/listinfo/mlug-listserv.mlug.ca

Reply via email to