473,386 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Exact difference

77
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?
Jan 8 '10 #1
9 1593
donbock
2,426 Expert 2GB
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.
Jan 8 '10 #2
alexis4
113 100+
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.
Jan 8 '10 #3
Time
77
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.
Jan 9 '10 #4
weaknessforcats
9,208 Expert Mod 8TB
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.
Jan 9 '10 #5
Time
77
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.
Jan 10 '10 #6
alexis4
113 100+
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!
Jan 10 '10 #7
Time
77
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.
Jan 10 '10 #8
alexis4
113 100+
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.
Jan 10 '10 #9
Banfa
9,065 Expert Mod 8TB
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.
Jan 10 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Hans Gruber | last post by:
Hi all, I have been struggling with a problem all day, I have been unable to come up with a working solution. I want to write a function which takes 2 unix timestamps and calculates the...
1
by: Santa | last post by:
Exact difference between 'const char *' and 'char *', also diff between 'const' and 'static', also at what conditions it can be used?. Thanks.
4
by: YS Sze | last post by:
If you know the exact longitude and latitude for a specific location, would anyone think it'd make any sense to find out if this set of location numbers is really part of the Fibonacci series or...
21
by: oksuresh | last post by:
Hi talents, I have noticed that atof() function approximates the string I pass to it. when I use atof() , as atof(" 184.64") and it returns 184.63999999999 But I would like to have...
14
by: Henning Hasemann | last post by:
Hi all, sounds trivial (I hope it is): Im searching for a way to get a time-value thats more exact than just seconds (i.e. I need milli- or microseconds or something similar, just at least as good...
7
by: alem | last post by:
Alem: hi friends I tried many methods but it will increase or decrease three or four months. Please help me to get exact year and month . thanks in advance.
8
by: =?Utf-8?B?QWxpY2U=?= | last post by:
Sorry for reposting here but I apparantly managed to pick the wrong discussion group earlier. Here's my story: Hi all, I am developping a simple application that displays an animated weather...
4
by: Jason Teagle | last post by:
I'm not sure which is the correct group to post this to, if either, so apologies for the crosspost and if it's OT. I have a Visual Studio.NET 2002-compiled solution that originated at work. At...
4
by: Yoavo | last post by:
Hi, I need to get the exact AssemblyVersion. I tried to use something like: string appName = System.Reflection.Assembly.GetAssembly(this.GetType()).Location; System.Reflection.AssemblyName...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.