LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-13-2002, 07:46 AM   #31
no2nt
Member
 
Registered: Aug 2001
Location: South Carolina, USA
Distribution: Redhat 8.0/Custom
Posts: 96

Rep: Reputation: 16

Are you referring to this statement from that link?

(italics are mine)
Quote:
In most C implementations, pointers are simply represented using natural
machine addresses, which are basically binary numbers. In segmented mainframe
architectures, a pointer might consist of two fields:
an object selector field,
and an offset into that object. The selector is an index into a descriptor
table, which holds the actual physical address of each described object, as
well as information about its size, access permissions and so on.
If so, it seems to depend on the machine's architecture and compiler. In the
case of a pointer utilizing two (or more) fields, then one could call a pointer
a data type or maybe even a data structure. That may be exactly the type
of architecture the Crays use. Would this be a incorrect conclusion?
 
Old 09-14-2002, 05:55 AM   #32
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,571

Rep: Reputation: 171Reputation: 171
It seems OK for me. I'm using only Intel machines (and Intel machines assembler, so I can talk only about it).
 
Old 09-15-2002, 11:13 AM   #33
sarin
Member
 
Registered: May 2001
Location: India, Kerala, Thrissur
Distribution: FC 7-10
Posts: 354
Blog Entries: 2

Rep: Reputation: 34
Hi, I was preparing for my exams ( This is my quiz week... ) And happen to see this. This is from the book "Data Structures And Algorithms" By Aho, Hopcroft and Ullman ( ISBN 81-7808-102-4 ). This is how it goes.

From chapter 1, section 1.3

"1.3 Data types, Data structures and Abstract Data Types.

........

A cell is the basic building block of data structures. We can picture a cell as a box that is capable of holding a value drawn from some basic or composite data type.

........"

( Under the same subsection )

"Pointers and cursors.

........
A pointer is a cell whose value indicates another cell.

........

A cursor is an integer valued cell, used as a pointer to an array. As a method of connection, cursor is essentially the same as the pointer,....

......."

I think this should clear all doubts. POINTER IS A DATA TYPE. IT CAN BE AN INTEGER OR SOME OTHER BASIC OR COMPOSITE DATA TYPE. ( Refer to the definition of cell )

--Sarin
 
Old 09-16-2002, 01:13 AM   #34
aditya
Member
 
Registered: Aug 2002
Distribution: RH 7.x
Posts: 71

Original Poster
Rep: Reputation: 15
Smile

Hi no2nt,
Sorry but you quoted the wrong lines. The lines of which I was talking about are:

'On the vast majority of implementations, all pointers have the same size, regardless of the type they point to, but you should not rely on that. All that is guaranteed is that void pointers and char pointers have the same size and representation.'

But yeah, that cray example you gave me, I had overlooked that. A pointer might be data structure on architectures and not on others. That's the inference I draw from your words. But, one more thing, I've read the generally intel besed processors, like the pentium series, are segmented architetures, so the segment descriptors etc. also aplly to them. (And they do, I know that).

And by the post of sarin, it's becoming more convincing that in general the pointer might be a data-type, if we leave the specifications of a particular language behind.

But this data-structure part needs more probing, as well as the lines I have just quoted from the site no2nt had given.

adi
 
Old 09-16-2002, 11:21 AM   #35
llama_meme
Member
 
Registered: Nov 2001
Location: London, England
Distribution: Gentoo, FreeBSD
Posts: 590

Rep: Reputation: 30
I don't think data structure and data type have an exact meaning. I know there are lots of books which have a little sentence saying what a data structure and a data type are, but that's just to help you understand the rest of the book; it's not a canonical definition.

I mean, if I define structure in C:

struct foo
{
int a;
int b;
};

Then I would say struct foo is a data type, but an instance of struct foo would be a data structure. However, you could also refer to struct foo as a data structure, and an instance of struct foo as an instance of a data structure. My point is that no-one has ever come up with a standard definition of these terms.

You could say a pointer is a data type, or that a pointer variable has a data type, etc., etc., but none of those terminologies would be any more correct than the other, IMHO.

Alex
 
Old 09-16-2002, 11:23 PM   #36
aditya
Member
 
Registered: Aug 2002
Distribution: RH 7.x
Posts: 71

Original Poster
Rep: Reputation: 15
Hi,
i think Alex has really something to say. So, we can safely say that pointer is a data-type after all. (Again, I'm not taking particular laguages into account).

But, I have something more to say. I happened to stumble upon my engg. notes one day, and as I ahd time I just galanced through them. Hence, I know that at least the intel 80x86 series is paged segmented architecture, but inherently segmented only, paging was added later on from 80386. Hence, all the addresses are in the form of
[segment no.]:[offset within segment].

When we write some address in C, then the compiller by default assumes that it is the offset, and the segment is assumed to be the one in which your program is running, ( I think it's most probably the data segment).

Through 'far' pointers or 'huge' pointers we can address other segments too, but then both the segment no, and offset have to be provided, as in the C function 'MK_FP'.

Again, when an interuupt occurs, the Interrupt Vector Table is organized as the [Code Segment]:[Intruction Pointer] data structures.

Though a pointer can't be data-structure in the sense that it is half int, and half float, it certainly can be in the sense that both the fields are integers (keeping in mind that pointers are integers, though with some constraints).

So, it seems to me that pointers are also data-structures. Flat addresses are generally not used in any machine since a very long time now.
 
Old 01-28-2014, 04:39 PM   #37
tanmaynagori
LQ Newbie
 
Registered: Jan 2014
Posts: 1

Rep: Reputation: Disabled
Well the reason of not having a pointer data type could be the size of the pointer variable.
Integer,characters,float double all have fixed sizes for a given machine.buT that is not the case with pointer variable.
pointer variable size depends upon the type of variable it points to.
Also Pointers can be dereferenced and there can be hierarchy of pointers(i.e pointer to a pointer to a pointer.....) which are not a property of other data type.
 
Old 02-03-2014, 10:13 AM   #38
Peverel
Member
 
Registered: May 2009
Location: Chelmsford, England
Distribution: OpenSuse 12.2 and 13.2, Leap 4.2
Posts: 120

Rep: Reputation: 24
Best here to go back to first principles. In a strongly typed language, which C is now, every datum has a type. This is used for two purposes: to define a location suitable for storing a datum and for type checking to ensure that, for example, assignments make sense. Thus, pointer is not a type, but describes a collection of types.

For example, int* is a data type derived from the base type int; it is not the same as int** nor as double*. The fact that in each case the datum is some flavour of integer is irrelevant here: the program treats them as all different.

One should avoid a possible fallacy: note that while it is true to say 3 is an int, it is quite untrue to say int is a 3.
 
Old 02-03-2014, 07:52 PM   #39
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 8,330
Blog Entries: 4

Rep: Reputation: 2843Reputation: 2843Reputation: 2843Reputation: 2843Reputation: 2843Reputation: 2843Reputation: 2843Reputation: 2843Reputation: 2843Reputation: 2843Reputation: 2843
A pointer is an integer-like variable whose value is understood to be a memory address (or zero, which is NULL, which simply means that the pointer points to nothing-at-all).

Pointers enable you to refer to locations in memory indirectly. Its most-common purpose is the construction of arbitrary data-structures in memory, using blocks of storage that are carved-out on demand via malloc() or what-have-you. (This function returns a pointer to the block of storage that was just allocated, which could be anywhere.)

Part of the definition of the pointer variable is to identify what sort of thing it "points to." (If you say void *, it means that you aren't telling the compiler what it points to.)

Point your finger at the wall. The pointer is your hand. What the pointer (currently) points to is the wall. So you can refer to the wall as "what the pointer is currently pointing-to." And you can, at any time, make it point to something else by loading a different memory-address value into it.

The only "gotcha" with regard to using pointers is that you must always know whether you are referring to the pointer itself (your hand ...), or the pointer's target (the wall, or whatever the pointer is currently pointing to). The syntax is not entirely un-ambiguous.

Last edited by sundialsvcs; 02-03-2014 at 08:00 PM.
 
Old 02-09-2014, 12:27 AM   #40
psionl0
Member
 
Registered: Jan 2011
Distribution: slackware_64 14.1
Posts: 722
Blog Entries: 2

Rep: Reputation: 123Reputation: 123
"Data type" is the vague thing. Any of the 4 options could be correct (except it is only a data structure) depending on which dictionary you use.
 
1 members found this post helpful.
Old 03-20-2016, 09:37 AM   #41
Dalwin
LQ Newbie
 
Registered: Mar 2016
Posts: 1

Rep: Reputation: Disabled
Hey guys I went through the whole discussion. The conclusion reached here was that pointer is a data type.

I was asked this question for an interview last week. And I answered that the pointer is a data type.

But the interviewer corrected me and said that the pointer is a data structure.

His view about it was, data structures are used to store data with some basic functionalities defined with it. And pointer qualifies this condition.

He said, i quote "a pointer stores the address of a variable, it also holds information on the type of data that should be held in that memory. This is a functionality of the pointer which is predefined hence making it a data structure."
 
Old 03-20-2016, 11:03 AM   #42
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,194

Rep: Reputation: 961Reputation: 961Reputation: 961Reputation: 961Reputation: 961Reputation: 961Reputation: 961Reputation: 961
These terms are quite "soft", especially without any context. Even if you choose a language, say C, the word 'pointer' can mean any or all of these:

Code:
a pointer constant -- (char *)300
a pointer variable -- argv
a type             -- FILE *
a data pointer     -- &errno
a code pointer     -- &main
a pointer to a built-in type -- int *p
a pointer to a compound type -- struct tm *
a pointer to another pointer -- char **argv
a pointer to a string-literal-- "literal"
(many other things I forgot to mention)

Last edited by NevemTeve; 03-20-2016 at 11:04 AM.
 
Old 03-20-2016, 11:57 AM   #43
psionl0
Member
 
Registered: Jan 2011
Distribution: slackware_64 14.1
Posts: 722
Blog Entries: 2

Rep: Reputation: 123Reputation: 123
Quote:
Originally Posted by Dalwin View Post
He said, i quote "a pointer stores the address of a variable, it also holds information on the type of data that should be held in that memory. This is a functionality of the pointer which is predefined hence making it a data structure."
The compiler might hold that information about a pointer but once the program is compiled to an executable, I think that you will find that the pointer variable contains nothing other than an address (at least, I can't see anything if I run gcc with the -S option).
 
Old 03-20-2016, 12:30 PM   #44
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: Slackware
Posts: 7,442

Rep: Reputation: 2818Reputation: 2818Reputation: 2818Reputation: 2818Reputation: 2818Reputation: 2818Reputation: 2818Reputation: 2818Reputation: 2818Reputation: 2818Reputation: 2818
...

Last edited by dugan; 03-20-2016 at 12:59 PM. Reason: My next one is better.
 
Old 03-20-2016, 12:32 PM   #45
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: Slackware
Posts: 7,442

Rep: Reputation: 2818Reputation: 2818Reputation: 2818Reputation: 2818Reputation: 2818Reputation: 2818Reputation: 2818Reputation: 2818Reputation: 2818Reputation: 2818Reputation: 2818
Quote:
Originally Posted by Dalwin View Post
He said, i quote "a pointer stores the address of a variable, it also holds information on the type of data that should be held in that memory. This is a functionality of the pointer which is predefined hence making it a data structure."
And that's not true for all C data types?

Honestly, if you get that question on an interview, I'd recommend walking out. Because, aside from the much-discussed merits of the question itself, they're plagiarizing interview questions from 2002 instead of coming up with their own.

Last edited by dugan; 03-20-2016 at 12:55 PM.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
redeferenced pointer to incomplete type Aldair1808 Programming 1 11-28-2005 03:23 PM
list<type> how can I make type be a pointer? exodist Programming 2 06-06-2005 08:40 AM
returning data to main() via a pointer to a pointer. slzckboy Programming 3 05-30-2005 01:20 PM
ereferencing pointer to incomplete type? ams Programming 5 03-03-2005 10:32 AM
Getting an incompatible pointer type error... JStew Programming 4 03-06-2003 05:08 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration