PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.c > sizeof(ptr) = ?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
sizeof(ptr) = ?

Réponse
 
LinkBack Outils de la discussion
Vieux 22/10/2007, 09h10   #1
William Xu
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut sizeof(ptr) = ?

I test it with char, short, int, long, float, double and struct
pointers, all return 4 bytes. Does the standard say anything about
sizeof a pointer? (I didn't find it in the standard...)

--
William

http://williamxu.net9.org
  Réponse avec citation
Vieux 22/10/2007, 09h13   #2
Ian Collins
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sizeof(ptr) = ?

William Xu wrote:
> I test it with char, short, int, long, float, double and struct
> pointers, all return 4 bytes. Does the standard say anything about
> sizeof a pointer? (I didn't find it in the standard...)
>

No, it is implementation specific.

--
Ian Collins.
  Réponse avec citation
Vieux 22/10/2007, 09h34   #3
Road Tang
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sizeof(ptr) = ?

William Xu wrote:

> I test it with char, short, int, long, float, double and struct
> pointers, all return 4 bytes. Does the standard say anything about
> sizeof a pointer? (I didn't find it in the standard...)
>


it's implementation defined.
e.g

on 32-bit machine, sizeof(ptr) may be 32
and 64-bit machine it returns 64.

Road
--
C FAQ: http://c-faq.com/
  Réponse avec citation
Vieux 22/10/2007, 09h34   #4
santosh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sizeof(ptr) = ?

William Xu wrote:

> I test it with char, short, int, long, float, double and struct
> pointers, all return 4 bytes. Does the standard say anything about
> sizeof a pointer? (I didn't find it in the standard...)


No. It says that a pointer of type void * must be capable of holding any
pointer value, but nothing specific is said about the sizes of
pointers. Pointers to different types could be of the same or different
sizes.

  Réponse avec citation
Vieux 22/10/2007, 09h57   #5
William Xu
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sizeof(ptr) = ?

Road Tang <roadtang@gmail.com> writes:

> it's implementation defined.
> e.g
>
> on 32-bit machine, sizeof(ptr) may be 32


Then, is it safe to say that sizeof(ptr) <= 32 ?

> and 64-bit machine it returns 64.


Similarly, sizeof(ptr) <= 64 ?

--
William

http://williamxu.net9.org
  Réponse avec citation
Vieux 22/10/2007, 10h01   #6
MisterE
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sizeof(ptr) = ?



>I test it with char, short, int, long, float, double and struct
> pointers, all return 4 bytes. Does the standard say anything about
> sizeof a pointer? (I didn't find it in the standard...)
>
> --
> William



Pointers of any type will have the same size because they hold the address
value of memory that they point to, thus they always hold the same type of
data. On standard PC's this is a 32bit address (4 bytes), but it depends on
the system what the size is.


  Réponse avec citation
Vieux 22/10/2007, 10h19   #7
Road Tang
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sizeof(ptr) = ?

William Xu wrote:

> Road Tang <roadtang@gmail.com> writes:
>
>> it's implementation defined.
>> e.g
>>
>> on 32-bit machine, sizeof(ptr) may be 32

>
> Then, is it safe to say that sizeof(ptr) <= 32 ?


No, I did't find the Standard have such rules about it.
I just write that number for example.

>> and 64-bit machine it returns 64.

>
> Similarly, sizeof(ptr) <= 64 ?
>

You like this apply? but I'm still not sure.


--
C FAQ: http://c-faq.com/
  Réponse avec citation
Vieux 22/10/2007, 10h29   #8
Martien Verbruggen
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sizeof(ptr) = ?

On Mon, 22 Oct 2007 14:04:59 +0530,
santosh <santosh.k83@gmail.com> wrote:
> William Xu wrote:
>
>> I test it with char, short, int, long, float, double and struct
>> pointers, all return 4 bytes. Does the standard say anything about
>> sizeof a pointer? (I didn't find it in the standard...)

>
> No. It says that a pointer of type void * must be capable of holding any
> pointer value, but nothing specific is said about the sizes of
> pointers.


Except, possibly, pointers to function.

Martien
--
|
Martien Verbruggen | You can't have everything, where would you
| put it?
|
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 05h49.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11053 seconds with 16 queries