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

Size of pointer to opaque object

``Opaque-pointer representing the ID of an object.
struct _objID;
typedef struct _objID * objectID;''

Hi again. Im using an api that defines an objectID type. The above
represents the
extent of the documentation on it.

The above means that objectID is defined as a pointer to an as yet undefined
class/struct _objID, and, if I understand the term correctly, is opaque in
so far as the actual nature of the _objID class/struct is as yet unknown,
yeah?

My problem is that I need to statically determine the size of an objectID. I
need to now that it occupies the same amount of space as 1,2,3... chars, but
without using sizeof(objectID). Is it possible? I was thinking that it might
be the same size as char* or something convenient like that.

TIA

Jul 19 '05 #1
12 4695
"Ellarco" <no****@eircom.net> wrote...
``Opaque-pointer representing the ID of an object.
struct _objID;
typedef struct _objID * objectID;''

Hi again. Im using an api that defines an objectID type. The above
represents the
extent of the documentation on it.

The above means that objectID is defined as a pointer to an as yet undefined class/struct _objID, and, if I understand the term correctly, is opaque in so far as the actual nature of the _objID class/struct is as yet unknown,
yeah?

My problem is that I need to statically determine the size of an objectID. I need to now that it occupies the same amount of space as 1,2,3... chars, but without using sizeof(objectID). Is it possible? I was thinking that it might be the same size as char* or something convenient like that.


The size of a pointer to any object is the same and is the same as
a pointer to void. So, you may use sizeof(void*) for your purposes.

Victor
Jul 19 '05 #2
Ellarco wrote:
....
My problem is that I need to statically determine the size of an objectID. I
need to now that it occupies the same amount of space as 1,2,3... chars, but
without using sizeof(objectID). Is it possible? I was thinking that it might
be the same size as char* or something convenient like that.


What is stopping you from using sizeof(objectID) ?

Jul 19 '05 #3

Victor Bazarov wrote:
[...]
My problem is that I need to statically determine the size of an objectID. I
need to now that it occupies the same amount of space as 1,2,3... chars, but
without using sizeof(objectID). Is it possible?
Yes. Use sizeof(_objID *).
I was thinking that it might
be the same size as char* or something convenient like that.


The size of a pointer to any object is the same and is the same as
a pointer to void.


Change the clinic, Bazarov.

regards,
alexander.
Jul 19 '05 #4

"Victor Bazarov" <v.********@attAbi.com> wrote in message news:L5*******************@rwcrnsc51.ops.asp.att.n et...
The size of a pointer to any object is the same and is the same as
a pointer to void. So, you may use sizeof(void*) for your purposes.

This is NOT true. A void* is required to hold a converted poitner value to
any object and have the same representation as char*, but it is not necessary
for it to be the same size as all the other pointers.

What is true however, is that the sizeof the pointer to any class has to be
the same size. If this were not true, than creating objects of type pointer
to incomplete classes, wouldn't be possible as the size would not be known.
However, this size can be smaller than sizeof(void*).
Jul 19 '05 #5
WW
Alexander Terekhov wrote:
[SNIP]
The size of a pointer to any object is the same and is the same as
a pointer to void.


Change the clinic, Bazarov.


Change the "cinic", Terekhov.

BTW it can make a whole lot of improvement in communication if you also say
want the point is, not only the insult part. :-)

--
Whitov Wolfov aka Attilov Feherov

Ps: Hota moja ckraju netchevo ne znaju (try to dechipher it, I'va heard it
from my father)
Jul 19 '05 #6

WW wrote:
[...]
BTW it can make a whole lot of improvement in communication if you also say
want the point is, not only the insult part. :-)
What would Ron do here, then?

--
Whitov Wolfov aka Attilov Feherov

Ps: Hota moja ckraju netchevo ne znaju (try to dechipher it, I'va heard it
from my father)


That was probably in reply to your mother asking (with some "elements"
of shouting) your father "Where's The Money Gone?" (or something like
that), I guess. ;-)
Jul 19 '05 #7
WW
Alexander Terekhov wrote:
Whitov Wolfov aka Attilov Feherov

Ps: Hota moja ckraju netchevo ne znaju (try to dechipher it, I'va
heard it from my father)


That was probably in reply to your mother asking (with some "elements"
of shouting) your father "Where's The Money Gone?" (or something like
that), I guess. ;-)


No, actually I was supposed to tell it to the Baltic state(s) borderguards
if they keep asking too many questions. :-)

--
WW aka Attila
Jul 19 '05 #8
Hello,

"Victor Bazarov" <v.********@attAbi.com> wrote in message news:<L5*******************@rwcrnsc51.ops.asp.att. net>...
"Ellarco" <no****@eircom.net> wrote...
``Opaque-pointer representing the ID of an object.
struct _objID;
typedef struct _objID * objectID;''
(...)
Hi again. Im using an api that defines an objectID type. The above
represents the extent of the documentation on it.

The above means that objectID is defined as a pointer to an as yet
undefined class/struct _objID, and, if I understand the term
correctly, is opaque in so far as the actual nature of the _objID
class/struct is as yet unknown, yeah?

My problem is that I need to statically determine the size of an objectID.

Just say 'sizeof (objectID)'.

To know the size of any object, you need the definition of its type.
But if you just want to know the pointer's size, you only need a
forward declaration; it works even with pointers to incomplete types.

(...)
The size of a pointer to any object is the same and is the same as
a pointer to void.


This is true in most platforms, but actually it's implementation
dependent.
++t;
Wagner
Jul 19 '05 #9
Wagner Bruna wrote:
Hello,

"Victor Bazarov" <v.********@attAbi.com> wrote in message news:<L5*******************@rwcrnsc51.ops.asp.att. net>...
The size of a pointer to any object is the same and is the same as
a pointer to void.

This is true in most platforms, but actually it's implementation
dependent.


This is an interesting assertion, and makes me think I don't unserstand
pointers correctly? I thought a pointer contained a memory address, and
that memory addresses had the same size regardless of what that address
is... Otherwise how would it be kosher for me to declare pointers to
undefined Classes. And since most any pointer can be cast to a pointer
to void, a pointer to void would have to be the same size.

Can you give me a counter example where the statement 'the size of a
pointer to any object is the same and [its size] is the same as a
pointer to void' does not hold true?

glen stark

Jul 19 '05 #10


glen stark wrote:

Wagner Bruna wrote:
Hello,

"Victor Bazarov" <v.********@attAbi.com> wrote in message news:<L5*******************@rwcrnsc51.ops.asp.att. net>...
The size of a pointer to any object is the same and is the same as
a pointer to void.

This is true in most platforms, but actually it's implementation
dependent.


This is an interesting assertion, and makes me think I don't unserstand
pointers correctly? I thought a pointer contained a memory address, and
that memory addresses had the same size regardless of what that address
is...


One needs to distuingish between objects of class type and objects
of builtin type. A character pointer may indeed have a different
size then a pointer to a class object.
Otherwise how would it be kosher for me to declare pointers to
undefined Classes.
pointers to class object have the same size. Although it
is not mentioned explicitely in the standard, it follows
from eg. what you say (forward declarations would not work).
And since most any pointer can be cast to a pointer
to void, a pointer to void would have to be the same size.
A void pointer could be larger then any other pointer. The only
requirement is, that any pointer can be cast to void* and back
without loosing information.

Can you give me a counter example where the statement 'the size of a
pointer to any object is the same and [its size] is the same as a
pointer to void' does not hold true?


Well. The standard does not require this. But AFAIK there have indeed
been machines where character pointers where treated differently due
to alignment restrictions on that CPU. Eg. if you know that an int
must always be stored at an address divisible by 4, then you know that
the last 2 bits of that address are always 0. So instead of storing
those 2 bits, you can shift the whole address 2 times to the right
and still haven't lost any information (but gained a larger address
room). But the same may not work for characters where you want to
address each and every byte.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 19 '05 #11

"glen stark" <ma**@glenstark.org.nospam> wrote in message news:3f********@pfaff2.ethz.ch...

This is an interesting assertion, and makes me think I don't unserstand
pointers correctly? I thought a pointer contained a memory address, and
that memory addresses had the same size regardless of what that address
is...
Your understanding is incomplete. A pointer is not a memory address. A pointer
is a data type that refers to a location in memory. The pointer is frequently
some hardware supported memory or register format. Not all machines just use
a 32-bit byte addressed value. Some machines have word based pointer types
and would to have additional information for addressing partial words which may
make the pointers to those types larger. The language forsees this. No where
in the document does it say pointers are the same size or even the same layout
with the exception that void* and char* are the same.
Otherwise how would it be kosher for me to declare pointers to
undefined Classes. And since most any pointer can be cast to a pointer
to void, a pointer to void would have to be the same size.


That's not true, a void pointer just has to be able to store a converted value
from any other pointer. The reverse is not true.
char x;
char* cp = (char*)(int*)(char*) &x;
The char* to int* conversion may lose information resulting in an invalid
conversion.
Jul 19 '05 #12
In article <3f********@pfaff2.ethz.ch>, ma**@glenstark.org.nospam
says...

[ ... ]
This is an interesting assertion, and makes me think I don't unserstand
pointers correctly? I thought a pointer contained a memory address, and
that memory addresses had the same size regardless of what that address
is...
Maybe, or maybe not. First of all, it's necessary to distinguish
between pointers to data and pointers to functions. Pointers to data
come in two varieties: pointers to global functions are one sort of
things, and all of them are compatible with each other. Pointers to
member functions are entirely different (and only rarely useful, so I
won't got into further detail about them for the moment).

Pointers to data have a few requirements: a pointer to void has the same
representation as a pointer to char, and any other kind of pointer can
be converted to a pointer to void and back to its original type without
losing information. Though not explicitly stated, the fact that a
pointer to char has the same representation as a pointer to void seems
to imply that you should be able to do the same thing (convert pointer
to some other type to pointer to char and back without losing anything).

Other than that, most bets are off -- different sorts of pointers could
have different sizes and representations. For one example, consider a
64-bit machine with word-addressing, but not byte-addressing. A pointer
to char on such a machine might consist of the address of a word AND the
number of a byte within that word.

Another possibility would be a machine that provided hardware support
for quite a bit of memory protection -- a pointer on such a machine
might include not only the address of the object, but also information
about things like the greatest legal offset from that address, so you
can't accidentally dereference a pointer outside its bounds.

Both of these (roughly) represent real machines -- Crays are similar to
the first, and AS/400's the second.
Otherwise how would it be kosher for me to declare pointers to
undefined Classes.
This can be handled a number of ways -- for one example, there might be
an optimized representation for a pointer under some circumstances, and
a less optimal version that will work under any circumstances. In this
case, a pointer based on a forward declaration would work, even though
it might be less efficient than would otherwise be the case.
And since most any pointer can be cast to a pointer
to void, a pointer to void would have to be the same size.


Not so -- a pointer to void basically has to be AT LEAST as large as any
other (i.e. has to be able to hold all the information in any other) but
could contain MORE information than a pointer to some other type.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jul 19 '05 #13

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

Similar topics

1
by: David Gilbert | last post by:
I'm trying to maintain the interface to KQueue for FreeBSD. At one point, the C module stores an opaque object in a C structure such that the opaque pointer can be used later by the application. ...
18
by: Tarundeep | last post by:
hi, let us say it is a 32 bit processor then the size of the pointer is 32 bits. now i want to know what would be the size of the class with vtable pointer in it , that is it has few virtual...
7
by: Alfonso Morra | last post by:
Straight of the bat, I'll admit this is not a nice solution, it is dangerous (not type safe) etc,etc, I know what the perils are. I don't need a lecture on why what I'm doing is perilous - that is...
18
by: Anand Buddhdev | last post by:
Hi everyone, I'm a C newbie, so please be gentle. I have a program that defines the following things: typedef union { unsigned int I; unsigned char b; } dword;
5
by: Danilo Kempf | last post by:
Folks, maybe one of you could be of help with this question: I've got a relatively portable application which I'm extending with a plugin interface. While portability (from a C perspective) is...
2
by: Kurt Ng | last post by:
Hi, y'all. Can anyone help me on this problem? I'm working with a third-party C dll, and I'm having trouble importing into C# the dll's methods that return one of the dll's defined types,...
11
by: quakewang | last post by:
hi, I have define in a head file like this: #define GLUT_BITMAP_9_BY_15 ((void*)2) #define GLUT_BITMAP_8_BY_13 ((void*)3) #define GLUT_BITMAP_TIMES_ROMAN_10 ...
36
by: gert | last post by:
Any comments why char **page doesn't reallocate #include <stdlib.h> void add(char **page,char *line,int n) { char **temp; if(temp=realloc(page,sizeof(char *)*(n+1))) {
4
by: Kenneth Brody | last post by:
I looked at my copy of n1124, and I didn't see anything about this particular situation... What happens if you realloc() to a size of zero? Implementations are allowed to return NULL on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.