LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 03-21-2016, 05:27 AM   #46
a4z
Senior Member
 
Registered: Feb 2009
Posts: 1,727

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742

Quote:
Originally Posted by aditya View Post
Ok,
but I still don't understand how could a pointer pointing to different structures or data types occuy different lengths. This I found at the site that no2nt has given.
because it points to the start address of what it is pointing to.
the type before the *, eg int*, tells the rest (size of data)

and pointers are types, of course, in some languages more noticeable than in others
 
Old 03-21-2016, 05:55 AM   #47
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,880
Blog Entries: 1

Rep: Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871
On some platforms the pointers themself might be of different length. Most infamous example is intel-8086 with its 'small data, large code', 'large data, small code', 'huge data, huge head-ache' combinations.
 
Old 03-21-2016, 06:43 AM   #48
a4z
Senior Member
 
Registered: Feb 2009
Posts: 1,727

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
Quote:
Originally Posted by NevemTeve View Post
On some platforms the pointers themself might be of different length. Most infamous example is intel-8086 with its 'small data, large code', 'large data, small code', 'huge data, huge head-ache' combinations.
hm, and the near and far pointer, let's be glad that they are gone, even if we still have to deal with artefacts of them (eg std::allocators where just a kind of hack to handle these pointers and where added just that MS would vote for the std to become standard, what they of course not did anyway.)
 
Old 03-21-2016, 07:08 AM   #49
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,691
Blog Entries: 4

Rep: Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947
In one crop of early smart-phones, they did come back. (And, in some embedded-controller applications, they still do.)
 
Old 03-21-2016, 11:28 AM   #50
psionl0
Member
 
Registered: Jan 2011
Distribution: slackware_64 14.1
Posts: 722
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
Quote:
Originally Posted by NevemTeve View Post
On some platforms the pointers themself might be of different length. Most infamous example is intel-8086 with its 'small data, large code', 'large data, small code', 'huge data, huge head-ache' combinations.
Whether a pointer is a "near" type or a "far" type, its size depends only on the addressing mechanism. It has nothing to do with the size of the data it is pointing to.
 
Old 03-21-2016, 11:28 AM   #51
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by Dalwin View Post
But the interviewer corrected me and said that the pointer is a data structure.
The original question of this thread was stupid, but that interviewer significantly stupider.

When you are doing anything other than quoting from a standards document English is far too ambiguous a language for this kind of question.

Even when you are quoting from a standards document, English tends to be too ambiguous.

The simplest and most general/abstract questions (such as the original one here) are the ones in which English fails the most at carrying actual meaning.

Within the overwhelming ambiguity of English, a "pointer" would most plausibly be a "pointer variable" which is neither a type nor a data structure. Stretching the meaning of "pointer" to be a type is a modest (but I think unsound) leap. Stretching the meaning of "data structure" to cover a reasonable meaning of "pointer" is much worse.
 
3 members found this post helpful.
Old 03-21-2016, 12:08 PM   #52
psionl0
Member
 
Registered: Jan 2011
Distribution: slackware_64 14.1
Posts: 722
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
Quote:
Originally Posted by johnsfine View Post
Within the overwhelming ambiguity of English, a "pointer" would most plausibly be a "pointer variable" which is neither a type nor a data structure.
That probably explains it best. A pointer is simply a variable that contains an address.

What type of variable is stored at that address depends on the rules of the compiler. Prior to the ANSI standard, C didn't do type checking and a pointer to a float variable could just as easily be regarded as a pointer to a character array without modifying the pointer variable at all. (You can still do this in assembler or FORTH). In ANSI C, you would have to do a type cast to change the type of variable the pointer references but the number stored in the pointer variable still doesn't change.
 
Old 03-22-2016, 08:49 AM   #53
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,691
Blog Entries: 4

Rep: Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947
I use the terms in this way:

Pointer: A variable whose value is understood to contain a memory address. The value "zero," a.k.a. NULL or "nil," by-convention is taken to mean that the pointer points to nothing at all.

Composite Data Type: Any construction, usually called a "struct" or "record," which consists of multiple simple data-types in a fixed arrangement, occupying consecutive bytes in memory.

Data Structure: An arbitrary arrangement of data in memory, ordinarily constructed from memory that is dynamically allocated ("on demand") from the heap. The members of the structure are Composite Data Types of various kinds. Because the memory for the structure is dynamically allocated, pointers are necessarily used to connect one part of the structure to other parts. (In "on-disc" data structures, record-numbers or file-positions serve the same role and purpose as do pointers in "in-memory" data structures.)
 
Old 07-30-2017, 07:43 AM   #54
delhiank762
LQ Newbie
 
Registered: Jul 2017
Posts: 2

Rep: Reputation: Disabled
pointer is a data type

hey aditya,
if u have read about the datatypes then you will find that they are classified as follows in C++
1)address pointer,references
2)logical bool
3)numeric intger,real\float
4)structure array,union,structure,class..


i hope you got the answer what actually the pointer is!!
thanks
 
Old 08-04-2017, 08:40 AM   #55
xahodo
Member
 
Registered: Oct 2009
Distribution: Gentoo Linux
Posts: 39

Rep: Reputation: 22
Strictly speaking, a pointer is just a number (like anything else in a computer). It's higher level languages that make things more complicated.

A pointer just points to a piece of memory. Nothing more. Attaching an identifier to it just makes life easier for the developer.
 
Old 08-04-2017, 08:49 AM   #56
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,691
Blog Entries: 4

Rep: Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947
Quote:
Originally Posted by xahodo View Post
Strictly speaking, a pointer is just a number (like anything else in a computer). It's higher level languages that make things more complicated.

A pointer just points to a piece of memory. Nothing more. Attaching an identifier to it just makes life easier for the developer.
A pointer is an integer-type variable whose value is understood to be a memory address. And, by convention, the value zero is NULL (or nil) – an indication that the value of the pointer is not significant; that "it doesn't point to anything at all."

I don't consider it to be a "data type" since it is the means to an end. It is not something of particular interest, except that it is the address of something that is interesting to somebody. It is the means of obtaining the address of "the data."

Last edited by sundialsvcs; 08-04-2017 at 08:51 AM.
 
Old 08-04-2017, 01:14 PM   #57
a4z
Senior Member
 
Registered: Feb 2009
Posts: 1,727

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
it is a data type, just it can be converted to and from int means not that it is an in
this
Code:
int* a; 
int b; 
a++ ;
b++ ;
does 2 total different things because integer and pointer are not of the same type



C++ did it's best to at least fix on problem with C++11
Code:
void foo(int);
void foo(bar*);

foo(NULL) ; // does not work , ambiguous because of implicit conversion -> BAD!
foo(nullptr) ; // works sind nullptr_t is a type

fortunately, in modern languages, lice C++ , raw pointers are not needed anymore and can be implemented as strong types that avoid the horrible and unsafe implicit conversion topic totally
example
https://a4z.bitbucket.io/blog/2017/0...y-toolbox.html

seeing pointers as what they are, types, and use them like this, avoids lots of the common mistakes that have lead, and still leads, to a lot of expensive problems with the pointer is a int approach
 
Old 08-05-2017, 04:58 AM   #58
Peverel
Member
 
Registered: May 2009
Location: Chelmsford, England
Distribution: OpenSuse 12.2 and 13.2, Leap 4.2
Posts: 128

Rep: Reputation: 24
C is a language. In any language, certain words have fixed meanings irrespective of what one "considers them to be" (Donald Trump and the Cheshire Cat tend to disagree, of course). In C, either K&R or ANSI, pointers are data types: thus, int* and int** are not only data types but different data types. The fact that both are stored as integers representing virtual addresses, is irrelevant.

A null pointer is a special case: its value is conventionally zero and it is automatically converted to whatever is the relevant type. Without strong typing, as in original versions of C, it was possible to assign an integer value to a pointer variable. This was useful when the addresses were real memory addresses, for example to access memory mapped I/O, no longer necessary or indeed possible with virtual addresses.
 
Old 08-05-2017, 05:55 AM   #59
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,880
Blog Entries: 1

Rep: Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871
Well, 'argv' parameter of 'main' is a pointer, but it isn't a data-type.
 
Old 08-05-2017, 08:40 AM   #60
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,691
Blog Entries: 4

Rep: Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947
Quote:
Originally Posted by NevemTeve View Post
Well, 'argv' parameter of 'main' is a pointer, but it isn't a data-type.
It would properly be called a "data structure."
 
  


Reply



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 06:10 PM.

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
Open Source Consulting | Domain Registration