Hi all,
Is it true that all pointer types that can be cast into void* (that
is, all pointer types with the exception of pointers to functions and
pointers to members) have the same size? And if not, do you know of
any examples of platform (OS + compiler) where such happens?
And does standard C++ guarantee the existence of a primitive (signed)
integer type T such that
sizeof(T) == sizeof(void*)
Even assuming the answer to the precedent question is negative (as I
suspect it is), suppose that in a given platform such an integer
primitive type T exists. Does anybody know of a way to single out such
a type, via some template or whatever?
TIA, with my best regards,
G. Rodrigues 5 1304
Gonçalo Rodrigues wrote:
Is it true that all pointer types that can be cast into void* (that
is, all pointer types with the exception of pointers to functions and
pointers to members) have the same size?
Yes.
And if not, do you know of
any examples of platform (OS + compiler) where such happens?
And does standard C++ guarantee the existence of a primitive (signed)
integer type T such that
sizeof(T) == sizeof(void*)
No. Check the documentation for your implementation.
Even assuming the answer to the precedent question is negative (as I
suspect it is), suppose that in a given platform such an integer
primitive type T exists. Does anybody know of a way to single out such
a type, via some template or whatever?
The only way exists is to confer with the documentation. There can be
a type that is non-standard. For example, on Win64, it's __int64.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Gonçalo Rodrigues wrote:
Hi all,
Is it true that all pointer types that can be cast into void*
4.10/2
An rvalue of type "pointer to cv T,", where T is an object type,
can be converted be converted to an rvalue of "pointer to cv void".
In other words, yes, so long as your const/volatileness is preserved.
(that
is, all pointer types with the exception of pointers to functions and
pointers to members)
note: 4.11/2 footnote 52 notes that "In particular, a pointer to member
cannot be converted to a void*".
>
And does standard C++ guarantee the existence of a primitive (signed)
integer type T such that
5.2.10/4 "A pointer can be explicitly converted to any integral type
large enough to hold it. The mapping function is implementation
defined. [Note: it is intended to be unurprising to those who know the
addressing structure of the underlying machine.]"
So yes, there exists, some type, but its type is implementation defined.
Note also, that 5.2.10/5 implies the reverse conversion exists as well.
sizeof(T) == sizeof(void*)
Even assuming the answer to the precedent question is negative (as I
suspect it is), suppose that in a given platform such an integer
primitive type T exists. Does anybody know of a way to single out such
a type, via some template or whatever?
Again, see above. Implementation defined. Your best bet is with,
#ifdefs, and either manifest defines, or your own architecture specific
defines.
Gonçalo Rodrigues wrote:
Is it true that all pointer types that can be cast into void*
Yes.
(that
is, all pointer types with the exception of pointers to functions and
pointers to members) have the same size?
No. The language guarantees that for any "regular" pointer type 'T*' the
round-trip conversion T* -void* -T* shall produce the original pointer
value. This means that, putting it informally, the amount of information stored
in the 'void*' pointer should be the same _or_ _greater_ than the largest amount
of information stored in any "regular" 'T*' pointer.
On platforms where pointer objects contain no internal padding that will mean
that physical size of 'void*' pointer (sizeof(void*)) will be the same _or_
_greater_ than physical size of any other "regular" pointer.
However, it is possible that on certain platform some pointer type 'T*' contains
lots of internal padding, i.e. parts of the pointer object that do not
participate in forming the actual pointer value. Physical size of such a pointer
can easily be greater than physical size of 'void*', while the above language
requirement will still be met.
And if not, do you know of
any examples of platform (OS + compiler) where such happens?
Hmm... Not immediately.
And does standard C++ guarantee the existence of a primitive (signed)
integer type T such that
sizeof(T) == sizeof(void*)
No. Note also that from purely pedantic point of view the fact that 'sizeof's of
two types are equal does not mean that both types use the same number of
value-forming bits.
Even assuming the answer to the precedent question is negative (as I
suspect it is), suppose that in a given platform such an integer
primitive type T exists. Does anybody know of a way to single out such
a type, via some template or whatever?
I don't think there's a portable way to do it.
--
Best regards,
Andrey Tarasevich
red floyd wrote:
Gonçalo Rodrigues wrote:
[snip]
>And does standard C++ guarantee the existence of a primitive (signed) integer type T such that
5.2.10/4 "A pointer can be explicitly converted to any integral type
large enough to hold it. The mapping function is implementation
defined. [Note: it is intended to be unurprising to those who know the
addressing structure of the underlying machine.]"
So yes, there exists, some type, but its type is implementation defined.
Where in that paragraph did you read that there exists an integral type
large enough to hold a pointer? All it says is that *if* you have such a
type, *then* you can cast. The question *whether* you have such a type is
not addressed as far as I can see.
[snip]
Best
Kai-Uwe Bux
Kai-Uwe Bux wrote:
red floyd wrote:
>Gonçalo Rodrigues wrote:
[snip]
>>And does standard C++ guarantee the existence of a primitive (signed) integer type T such that
5.2.10/4 "A pointer can be explicitly converted to any integral type large enough to hold it. The mapping function is implementation defined. [Note: it is intended to be unurprising to those who know the addressing structure of the underlying machine.]"
So yes, there exists, some type, but its type is implementation defined.
Where in that paragraph did you read that there exists an integral type
large enough to hold a pointer? All it says is that *if* you have such a
type, *then* you can cast. The question *whether* you have such a type is
not addressed as far as I can see.
Good point. The correct answer, is that "there *may* exist some type,
but its implementation defined (if it exists at all)". This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ellarco |
last post by:
``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
|
by: Jackie |
last post by:
Does anyone know how to get a count for a pointer to an array
for example
double** someFnct () {
cout <<"Enter num of row: " <<endl;
cin >> n;
cout <<"Enter num of column: " <<endl;
|
by: Fabian Wauthier |
last post by:
Hi list,
I am trying to dynamically grow a 2 dimensional array (Atom ***Screen) of
pointers to a struct Atom (i.e. the head of a linked list). I am not
sure if this is the right way to do it:
/* Allocate 1st dimension */
if((Screen = (Atom ***) malloc(sizeof(Atom **) * Width)) == NULL)
perrexit("malloc");
|
by: junky_fellow |
last post by:
According to Section A6.6 Pointers and Integers (k & R)
" A pointer to one type may be converted to a pointer to another type.
The resulting pointer may cause
addressing exceptions if the subject pointer does not refer to an
object suitably aligned in storage. It is
guaranteed that a pointer to an object may be converted to a pointer to
an object whose type requires less
or equally strict storage alignment and back again without change;...
|
by: siliconwafer |
last post by:
What is size of pointer in C on DOS?
is it sizeof(int ) or size of (long int)?
If this ans is present in FAQ pls direct me to tht ouestion
| |
by: yezi |
last post by:
Hi, all:
I want to record some memory pointer returned from malloc, is possible
the code like below?
int memo_index;
int i,j;
char *tmp;
for (i=0;i<10;i++){
|
by: elmar |
last post by:
Hi Clers,
If I look at my ~200000 lines of C code programmed over the past 15
years, there is one annoying thing in this smart language, which
somehow reduces the 'beauty' of the source code ;-):
char *cp;
void *vp;
void **vpp;
|
by: josh |
last post by:
Why if I use:
Array *Array::operator=( const Array *right )
{
if ( right != this )
{ // check for self-assignment
// for arrays of different sizes, deallocate original
// left side array, then allocate new left side array.
if ( size != right->size )
{
|
by: sumedh..... |
last post by:
double * X
size of X->??
size of X->??
double (*X)
size of X->??
size of X->??
|
by: ladesidude |
last post by:
Hi,
I have this program in C, and have commented each line as per my understanding. At the end, I have some questions which I havent been able to understand. Any help would be appreciated.
#include <stdio.h>
#define Size1 (4)
#define Size2 (3)
|
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...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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();...
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |