Exact difference

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Time
    New Member
    • Jan 2010
    • 77

    Exact difference

    Logically speaking pointer points to a variable of given type.
    for ex. integer will hold some value where as pointer to it will store address of that integer in memeory allocated to it. *(value of) operator will give value of integer to which it is pointing. Value and address both are integers.
    So from memeory point of view there is no difference. So what makes pointer behave differently; have other operations than non-pointers.. i know there must be code written for those operators in pass 1 or so on but sometimes value of non-pointer variable and pointers can also be same. So, i want to know wats making them different in memory, so as to identify them separately?
  • donbock
    Recognized Expert Top Contributor
    • Mar 2008
    • 2427

    #2
    Ultimately all values in your program (including the instructions themselves) are binary bit-patterns. However, it is rarely useful to think in terms of this ultimate commonality.

    Similarly, while you're right that values and addresses are ultimately binary integers it isn't helpful to dwell on that commonality. Instead high-level languages "pretend" that these entities are different. They do this so that they can enforce semantic distinctions between them. For instance, you can't dereference an integer, you can't divide one pointer by another, etc.

    Notice these limitations are imposed by the high-level language on its source code. There is nothing in memory that enforces any such semantic limitation. In fact, you could write an assembly language subroutine that, for example, divides one pointer value by another.

    Comment

    • alexis4
      New Member
      • Dec 2009
      • 113

      #3
      You cannot directly divide pointers neither in assembly (at least in MCU architectures I am aware of) except by a user subroutine, as well marked by donbock. Divisions are only accomplished through fast registers (like let's say accumulator), so you must first load pointer values to specific registers and then divide these registers. You can then re-save the result at an address shown by a pointer. Like in C, but in lower level!
      One of the needs of pointers (indirect addressing) in assembly is to access external memory. 8-bit MCUs accessing 16-bit external memories. So the idea is to have a 16-bit (two 8-bit actually) register with an address stored in it, showing the external memory address to be accessed by a register. But I suppose that even a 32-bit MCU will access a 16-bit memory with pointers, due to databus and clocking reasons.
      In C the great thing about pointers is that they let you "call-by-reference", so multiple values can be returned from a single function. And let's not forget file pointers.
      Generally the higher the language level is, the less pointers are needed, because a high level language manage low level operations by itself, except when user needs to drop low.

      Comment

      • Time
        New Member
        • Jan 2010
        • 77

        #4
        Yeah i agree that in memeory everything is in terms of binary.. i was just wondering how pointers are identified in processing; i guess there must be some flag kind of entries in symbol table along with them.... Is there any way i can read the routines for it which differentiates between pointer and non-pointer.

        Comment

        • weaknessforcats
          Recognized Expert Expert
          • Mar 2007
          • 9214

          #5
          Originally posted by Time
          i was just wondering how pointers are identified in processing;
          There is no identificatrion of pointers during processing. No identification of variables or functions either. All you have is a pile of bits. The code you write are your instructions to the compiler for bit generation.

          It is the compiler that has arranged everything so it will work. That's why typecasts are so nasty since they override the compiler and therefore can cause a bad binary to be produced.

          Remember a pointer is just an address variable. It has no type. The type you associate with a pointer tells the compiler what sort of address can be stored in the pointer. If this gets messed up then all of the pointer arithmetic generated by the compiler won't work.

          Comment

          • Time
            New Member
            • Jan 2010
            • 77

            #6
            There is no identificatrion of pointers during processing. No identification of variables or functions either
            .

            This is absolutely ridiculous when you consider processing of a compiler.
            You havn't read the word symbol table in my earlier post. I know very well that compiler is used for converting your code in binary rather assembly and assembler is used for converting it in binary.
            I am asking about compilers processing dude.

            Another big mistake in your concepts:
            The type you associate with a pointer tells the compiler what sort of address can be stored in the pointer
            .
            The type you associate with a pointer tells the compiler what sort of variable it can point to; specifying which type of variables address it can store..in short telling the type of variable its pointing to.

            Not what sort of address.
            Address is always in integers there is no sorting in addresses.

            Comment

            • alexis4
              New Member
              • Dec 2009
              • 113

              #7
              Hey this is very rude of you!!!
              You start a thread with a simple question as "difference between integer and pointer" and you now show yourself holding all the answers and insulting people who are trying to help you?
              This thread should be consider solved from the second answer. Donbock gave a full answer, I told you about call by reference and file pointers, what more do you want? Open a book or try a google search in less than a second and you will find what you want! And are we supposed to know what compiler you are using? Open your compiler's book and read about it!
              I helped you in the first place, but I am telling you that I believe these kind of threads (along with others like "size of null") should not be answered. You will find your answer in google in less time than waiting for someone to answer in a forum.
              Forums are for solving problems. I understand that even a professional may stuck on something simple and because he possibly works alone he enters a forum and ask a question. And the answer may come from someone who is 10 times less experienced, this can happen. But enter a forum, asking theoretical questions, getting answers and insulting people because their answers considered to be short (according to you!), this is really frustrating!

              Comment

              • Time
                New Member
                • Jan 2010
                • 77

                #8
                I never said that the reply is short, reply is not about what i am asking..
                In my first post itself i have stated that
                from memeory point of view there is no difference
                .. may be i asked in wrong words as i wrote
                wats making them different in memeory
                ..meaning which process in pass1 is differentiating the two.

                And for rest of the things; if you feel that theorotical quetions should not be answered ; you dont answer them.

                What is wrong will remain wrong wether you find it rude or not.

                Comment

                • alexis4
                  New Member
                  • Dec 2009
                  • 113

                  #9
                  I answered your question in the first place didn't I? I am just telling that a search machine can give you many more answers about these kind of questions than 2-3 posts within a thread. Not to say that your question has been covered by all previous posts!
                  Anyway, I hope you 'll find answers to your question. Really.

                  Comment

                  • Banfa
                    Recognized Expert Expert
                    • Feb 2006
                    • 9067

                    #10
                    Originally posted by Time
                    Not what sort of address.
                    Address is always in integers there is no sorting in addresses.
                    You are very very wrong here. The pointers on your platform may be stored as integers on your platform but the standard does not require it. Additionally the standard does not require that pointers to different types have the same form, in fact the standard makes no requirement on pointers other than they are meaningful to the platform to locate data in memory.

                    If you worked on any platform that used word addressing rather than byte addressing you would know this since typically on such platforms char * and void * have 1 more bit that all other pointers in order to indicate which byte in the word addressed is to be accessed.

                    I imagine there is a good chance you believe NULL pointers actual have the value 0 too so just in case let me say that actually it is the compilers responsibility to convert the value 0 used in a pointer context to the platforms representation of a NULL pointer which can be anything.


                    And to answer your question how does the compiler identify a pointer as opposed to a pointer in the symbol table. There is no such identification. The symbol table is a contiguous collection of all the variables that the program has, it does not contain any information on what those symbols might be used for.

                    On the other hand the symbolic debugging information does store such information normally to facilitate debugging. What is stored in that table in really down to the writers of the compiler and debugger. There is no standard form for debugging information and in fact looking at Microsoft debuggers alone you can see that the information stored has changed 2 or 3 times over the last few decades.

                    Comment

                    Working...