473,789 Members | 2,799 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

double pointers

Do all double pointers have same size on a particular implementation.

eg char **c_ptr;
int **i_ptr;

Is the size of c_ptr and i_ptr always same (on same implementation)
or it may be different ?

Nov 14 '05 #1
11 2202
ju**********@ya hoo.co.in wrote:

Do all double pointers have same size on a particular implementation.

eg char **c_ptr;
int **i_ptr;

Is the size of c_ptr and i_ptr always same (on same implementation)
or it may be different ?


It may be different.

--
pete
Nov 14 '05 #2
ju**********@ya hoo.co.in wrote:
Do all double pointers have same size on a particular implementation. eg char **c_ptr;
int **i_ptr; Is the size of c_ptr and i_ptr always same (on same implementation)
or it may be different ?


They may be different. They point to different types (which happen
to be pointer types, but this is irrelevant here).
Eg. all of these may have different sizes:
char *pc;
short *ps;
int *pi;
struct s *pst;
union u *pun;
short * *pps;
int * *ppi;
int ** *ppi;
struct s * *ppst;
struct s2* *ppst2;
int ****** *p7i;
void (*pvf)(void);
int (*pif)(void);
const int (*pcif)(void);
int (*pifi)(int);
int (*pifii)(int, int);
etc...

What we only know is that pointer to void and pointer to char
have the same representation, therefore the same size, and that
they must be able to hold all other pointer-to-object values
(after conversion).

However it doesn't follow that their size must be greater or equal
to other pointers (eg. other pointers could have padding bits,
or other information encoded, that make them fatter that absolutely
necessary).

Apart of that, pointers to structs, unions and un/qualified compatible
types have to have the same representation (and size) within
their respective group.

--
Stan Tobias
mailx `echo si***@FamOuS.Be dBuG.pAlS.INVALID | sed s/[[:upper:]]//g`
Nov 14 '05 #3
<snip>
Apart of that, pointers to structs, unions and un/qualified compatible
types have to have the same representation (and size) within
their respective group.


Can you please elaborate this ? Also, what do you mean by nu/qualified
compatible types ?

Nov 14 '05 #4


S.Tobias wrote:
ju**********@ya hoo.co.in wrote:
Do all double pointers have same size on a particular implementation.
eg char **c_ptr;
int **i_ptr;


Is the size of c_ptr and i_ptr always same (on same implementation)
or it may be different ?

They may be different. They point to different types (which happen
to be pointer types, but this is irrelevant here).
Eg. all of these may have different sizes:


Chapter and verse please for my clarification.

<snip>
Apart of that, pointers to structs, unions and un/qualified compatible
types have to have the same representation (and size) within
their respective group.


couldnt get that. Do you mean sizeof (struct *a) == sizeof (union *b)
etc !

- Ravi
Nov 14 '05 #5
Ravi Uday wrote:
S.Tobias wrote:
.... snip ...
Apart of that, pointers to structs, unions and un/qualified
compatible types have to have the same representation (and
size) within their respective group.


couldnt get that. Do you mean sizeof (struct *a) == sizeof
(union *b) etc !


Yes. This is needed so self-referencing structures can be created,
as in:

struct blah {
struct blah *next;
whatever info;
}

because the need for struct blah * size arises before struct blah
has been defined.

--
"I conclude that there are two ways of constructing a software
design: One way is to make it so simple that there are obviously
no deficiencies and the other way is to make it so complicated
that there are no obvious deficiencies." -- C. A. R. Hoare
Nov 14 '05 #6
ju**********@ya hoo.co.in wrote:
<snip>
Apart of that, pointers to structs, unions and un/qualified compatible
types have to have the same representation (and size) within
their respective group.
Can you please elaborate this ? Also, what do you mean by nu/qualified
compatible types ?


Short for "qualified and unqualified versions of compatible types" :)

(n869.txt)
# [#27] A pointer to void shall have the same representation
# and alignment requirements as a pointer to a character type.
# Similarly, pointers to qualified or unqualified versions of
# compatible types shall have the same representation and
# alignment requirements.28 ) All pointers to structure types
# shall have the same representation and alignment
# requirements as each other. All pointers to union types
# shall have the same representation and alignment
# requirements as each other. Pointers to other types need
# not have the same representation or alignment requirements.

These have to have same representation (and size):
struct s1 *pst1;
struct s2 *pst2;

These too:
union u1 *pun1;
union u2 *pun2;

These don't:
struct s1 *pst1;
union u1 *pun1;
and neither do these (incompatible pointed to types):
struct s1 * *ppst1;
struct s2 * *ppst2;

These don't have to have the same representation:
signed int *psi;
unsigned int *pui;

These have to (pointed-to types differ in qualification):
int *pi;
const int *pci;

These don't (incompatible pointed to types):
int * *pi;
const int * *pci;
but these have to (pointed to types differ in const qualification):
int * *pi;
int * const *pci;
and so do these:
const int * *pi;
const int * const *pci;

These have to (compatible types):
int (*paI)[];
int (*paC)[7];
and it can be deduced (by association), that these also
have to (although it's not explicitly demanded; pointed
types are incompatible):
int (*pa7i)[7];
int (*pa9i)[9];

These have to (different, but compatible pointed-to types):
void (*pvf )();
void (*pvfi)(int);
and it can be deduced (similarly as for the arrays above) that
these have to, too:
void (*pvfv)(void);
void (*pvfi)(int);
void (*pvfid)(int, double);
but these don't (incompatible pointed to types):
void (*pvf)();
int (*pif)();
and neither do these:
void (* *ppvfv)(void);
void (* *ppvfi)(int);

These probably may have different representation:
const int (*pcif)();
int (*pif )();
but this is arguable (formally function types are different, but functions
return rvalues which lose qualifiers).

--
Stan Tobias
mailx `echo si***@FamOuS.Be dBuG.pAlS.INVALID | sed s/[[:upper:]]//g`
Nov 14 '05 #7


CBFalconer wrote:
Ravi Uday wrote:
S.Tobias wrote:

... snip ...
Apart of that, pointers to structs, unions and un/qualified
compatible types have to have the same representation (and
size) within their respective group.


couldnt get that. Do you mean sizeof (struct *a) == sizeof
(union *b) etc !


Yes. This is needed so self-referencing structures can be created,
as in:

struct blah {
struct blah *next;
whatever info;
}

because the need for struct blah * size arises before struct blah
has been defined.


I not making the connection here. Why does this require that
sizeof(struct *a) == sizeof(union *b) and from where in the Standard to
you conclude that this statement is guaranteed to be true?

Robert Gamble

Nov 14 '05 #8
ju**********@ya hoo.co.in writes:
Do all double pointers have same size on a particular implementation.

eg char **c_ptr;
int **i_ptr;

Is the size of c_ptr and i_ptr always same (on same implementation)
or it may be different ?


Several people have already answered this; there's no requrement for
them to be the same size. (BTW, the phrase "double pointers" is
potentially misleading; I initially thought you meant double*.)

My question is, why does it matter? How does knowing or not knowing
that char** and int** may not be the same size affect the way you read
or write C programs? It's possible to write code that depends on the
assumption that they're the same size, but it's nearly impossible to
write *good* code that does so.

If you're asking out of idle curiosity, that's fine; idle curiosity is
a good thing (legends about cats notwithstanding ). But if you intend
to make use of the information, my advice is that you almost certainly
don't need to. For most C programming, there's little need to mix
pointers of different types. For the cases where it's necessary, the
language's guarantees about conversions to and from void*, and the
equivalent representation of void* and character pointer types, should
be sufficient -- and does not depend on the sizes of the pointers.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #9
Robert Gamble wrote:
CBFalconer wrote:
Ravi Uday wrote:
S.Tobias wrote:

... snip ...

Apart of that, pointers to structs, unions and un/qualified
compatible types have to have the same representation (and
size) within their respective group.

couldnt get that. Do you mean sizeof (struct *a) == sizeof
(union *b) etc !


Yes. This is needed so self-referencing structures can be created,
as in:

struct blah {
struct blah *next;
whatever info;
}

because the need for struct blah * size arises before struct blah
has been defined.


I not making the connection here. Why does this require that
sizeof(struct *a) == sizeof(union *b) and from where in the Standard
to you conclude that this statement is guaranteed to be true?


Because, to saw off enough space to hold a struct blah, you have to
know how much room a struct blah * takes (with the above
definition). Thus the size and alignment of a struct blah * cannot
depend on the size of a struct blah.

--
"I conclude that there are two ways of constructing a software
design: One way is to make it so simple that there are obviously
no deficiencies and the other way is to make it so complicated
that there are no obvious deficiencies." -- C. A. R. Hoare
Nov 14 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2788
by: Venkat | last post by:
Hi All, I need to copy strings from a single dimensional array to a double dimensional array. Here is my program. #include <stdio.h> #include <stdlib.h>
7
1714
by: ffld | last post by:
Greetings all i am having a horrible time trying to pass a 2 dimensional array of doubles to a function... basically a watered down version of my code looks like: void t1(double a); int main() { double d; d = 2.3;
12
9893
by: Sydex | last post by:
When I compile code I get error C2664: 'Integration::qgaus' : cannot convert parameter 1 from 'double (double)' to 'double (__cdecl *)(double)' in this part : double Integration::quad2d(double (*func)(double,double)) { nfunc = func ; return qgaus(f1,x1,x2);//error there
4
3605
by: JS | last post by:
I have a file called test.c. There I create a pointer to a pcb struct: struct pcb {   void *(*start_routine) (void *);   void *arg;   jmp_buf state;   int    stack; };   struct pcb *pcb_pointer;
3
1477
by: Peteroid | last post by:
I'm using VS C++.NET 2005 Express in /clr. How do I create, and then use, a '^' pointer to a 'double'? That is, assuming its possible, please fill in the question marks below (there are two of them): double x = double(7) ; double y ; double^ x_ptr = ?x ; y = ?x_ptr ; // y = double(7)
2
1544
by: Paminu | last post by:
I am implementing a double-linkedlist in C. I have defined some pointers that points to different locations in my list. Before using the list I will initialize these pointers and when I call insert/delete etc they will be changed. Instead of giving each funtion these pointers as argumentens I was wondering if it was possible to place them i a .h file and initialize them there. When a function changes the pointers they will be updated in...
42
5348
by: xdevel | last post by:
Hi, if I have: int a=100, b = 200, c = 300; int *a = {&a, &b, &c}; than say that: int **b is equal to int *a is correct????
2
2181
by: anon.asdf | last post by:
Hi! Q. 1) How does one write: sizeof(array of 5 "pointers to double") ??? I know that sizeof(pointer to an array of 5 doubles) can be written as: sizeof(double (*));
4
7579
by: Sagaert Johan | last post by:
Hi I am struggling with pinvoke I have dll a function that is declared as : sf_command (IntPtr sndfile,int command, IntPtr data, int datasize); i need to pass a pointer to a double in the data parameter, i now did : IntPtr mem = Marshal.AllocHGlobal(sizeof(double));
0
9665
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10408
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10199
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9020
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6768
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5417
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4092
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3697
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.