A good book on pointers,memory and some inner workings of compilers for C++

This is a discussion on A good book on pointers,memory and some inner workings of compilers for C++ within the C++ Programming forums, part of the General Programming Boards category; I am searching for a book(s) which explains things like the following - 1. Difference between memory allocation of local ...

  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    1

    A good book on pointers,memory and some inner workings of compilers for C++

    I am searching for a book(s) which explains things like the following -

    1. Difference between memory allocation of local and global (or other static variables)....? (or why i cant initialize a global variable more than once outside main and all other functions)

    2. Holes in structures, and structures and pointers.

    3. Deep concepts in pointers, objects, classes.....i mean relation between pointers and OOP.

    4. near, far, Huge pointers.

    5. Some insight into how the compiler does something....I dont want to know the exact details of compiler working, but there are some concepts I feel can be better understood if i know how compiler does it.

    I have already tried Pointers In C by Yashwant Kanetkar and didnt find it very useful.
    I am finding that the C++ Programming Language by Bjarne Stroussoup answers some of these questions, but i want a bit more detail, and a dedicated book for this.

    I found that a book named "C++ Pointers and Dynamic memory management by Michael C. Daconta " which seems to hold these answers, but i cant find the book anywhere in my city to get it and see if its really worth it (and there's no preview on internet). So please tell me if its a good book for this purpose, so i can order it online.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,592
    > 4. near, far, Huge pointers.
    Not worth knowing, unless you're maintaining 20 year old code with a 20 year old compiler.

    > 5. Some insight into how the compiler does something
    Can be dangerous.
    Far too many people fall into the "it works for me" trap.
    If what you learn about how the "froboz 3.2 compiler" starts to affect how you write your programs, then it's a sure bet that you're going to have a hell of a lot of trouble adjusting to the "codemusher 4.34 compiler" sometime later.
    You should write your code to the standard, not the compiler.

    > 2. Holes in structures, and structures and pointers.
    What about them?
    Like I said, most of the time, it's not that interesting.
    When it does become interesting, you'll be well into your programming career.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by hypernova View Post
    I am searching for a book(s) which explains things like the following -

    1. Difference between memory allocation of local and global (or other static variables)....? (or why i cant initialize a global variable more than once outside main and all other functions)
    Why would you WANT to initialize a global variable several times before main? It makes absolutely no sense to do that.
    2. Holes in structures, and structures and pointers.
    See Salem's answer.
    3. Deep concepts in pointers, objects, classes.....i mean relation between pointers and OOP.
    In theory there is no relation between OOP and pointers - why do you think there is one?
    However since we work in a pracital world and the saying goes "In theory, practice and theory work the same, in practice, theory and practice can be quite different", pointers are sometimes necessary to implement some of the object oriented concepts in C++ - particularly when it comes to virtual functions and abstract types. Scott Meyers books are good in learning object oriented programming in C++ - it's not about learning about pointers and how they are used in OOP, it's about learning OOP and when to use pointers. You are going about it the wrong way - you are learning to fix cars by learning the science behind nuts and bolts, not how a car works. Wrong way around. If you NEED to know more about nuts and bolts later on when you know how a car works, it will be quite easy to learn. But you won't learn how a car works by learning more about nuts and bolts. Likewise, you will not understand OOP better by knowing more about pointers. You will understand more about pointers simply by understanding more about OOP.
    4. near, far, Huge pointers.
    Do not bother, unless you are in the 20-year old code with 20-year old compilers, as Salem says. far, near, huge are non-standard, and only applicable on systems using 16-bit segment + offset type pointers. This is obsolete since Windows 3.1 came out (or OS/2 2.x if you prefer). No sane programmer should be using 16-bit compilers today.

    If you see code which uses far, near or huge pointers, then you should try looking for different source.
    5. Some insight into how the compiler does something....I dont want to know the exact details of compiler working, but there are some concepts I feel can be better understood if i know how compiler does it.
    Compiler technology is a VERY complex subject. I have worked for 20 years as a professional programmer, and I haven't got the skills to write a compiler. Nor do I always know what the compiler will do (I usually have a good idea, but not 100% sure).

    Studying the assembler code produced by the compiler is one way that have taught me al lot about compilers. But I still would need to know a lot more to be fully knowledgeable on what the compiler actually does.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    Inside the C++ Object Model
    Amazon.com: Inside the C++ Object Model: Stanley B. Lippman: Books

    I'm only a chapter in at this point, but the book is a very interesting read. Discusses how C++ does or might implement OO structures.

    As for the memory management of compilers (globals, statics, etc.) it is usually dependent on the compiler itself and how it decides to layout everything (and changes with optimization options). However, don't let that get you down -- it is indeed important to know this stuff, even if there are variations between compilers. The topics concerning this would cover memory management, compilation process, linker process, program loading process, etc. Sounds like part of an operating systems book along with part of a compiler construction book.
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21