473,320 Members | 1,876 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,320 software developers and data experts.

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 2168
ju**********@yahoo.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**********@yahoo.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.BedBuG.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**********@yahoo.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**********@yahoo.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.BedBuG.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**********@yahoo.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_Keith) 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
CBFalconer wrote:
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.


What does this have to do with unions though?

Robert Gamble

Nov 14 '05 #11
CBFalconer <cb********@yahoo.com> writes:
Robert Gamble wrote:

[...]
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.


That implies that all struct pointers have to be the same size, and
that all union pointers have to be the same size. It doesn't imply
that struct pointers have to be the same size as union pointers
(though I'd bet they are on everything other than the DS9K).

--
Keith Thompson (The_Other_Keith) 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 #12

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

Similar topics

4
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
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...
12
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...
4
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; }; ...
3
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...
2
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...
42
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
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
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.