|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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/ |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
>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. |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
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/ |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
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? | |
|
|
|
#9 |
|
Messages: n/a
Hébergeur: |
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. It is likely though, as you have just asserted that a pointer is less than 32 _bytes_ long... If you meant 32-bits, definitely no. Prime for example had an 32-bit architecture with 48-bit pointers ... |
|
|
|
#10 |
|
Messages: n/a
Hébergeur: |
MisterE 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...) >> >> -- >> 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. The standard doesnt state this. and it doesn't have to be the case. Prime, for example, had 32-bit pointers for integer, short, long etc but 48-bit pointers for char, if I remember correctly. |
|
|
|
#11 |
|
Messages: n/a
Hébergeur: |
William:
> 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...) The only thing required by the Standard is that sizeof(ptr) >= 1. There's no need to know in portable programming... just use sizeof(type*) where applicable. Martin |
|
|
|
#12 |
|
Messages: n/a
Hébergeur: |
Mark Bluemel <mark_bluemel@pobox.com> writes:
> No. It is likely though, as you have just asserted that a pointer is > less than 32 _bytes_ long... > > > If you meant 32-bits, definitely no. Prime for example had an 32-bit > architecture with 48-bit pointers ... Ah, yes, i meant 32-bits...;-) I get it now. Thanks for all the . -- William http://williamxu.net9.org |
|
|
|
#13 |
|
Messages: n/a
Hébergeur: |
On Oct 22, 1:34 am, Road Tang <roadt...@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...) > > it's implementation defined. > e.g > > on 32-bit machine, sizeof(ptr) may be 32 > and 64-bit machine it returns 64. I don't think this is true for any 32-bit 0r 64-bit system that has ever exsited. While sizeof(some ptr) may indeed be 32 or 64 (even though it seems unlikely), it has nothing to do with whether the system is a 32 bit or 64 bit system. (I wonder if there is enough memory in the entire world to fully populate a system with a 64 BYTE pointer.) |
|
|
|
#14 |
|
Messages: n/a
Hébergeur: |
On Oct 22, 2:01 am, "MisterE" <Mist...@nimga.com> 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...) > > > -- > > 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. While this may be true in your experience, the C standard imposes no such restriction. Furthermore, there are systems for which it is not true. |
|
|
|
#15 |
|
Messages: n/a
Hébergeur: |
Barry Schwarz <schwarz45@yahoo.com> writes:
> On Oct 22, 2:01 am, "MisterE" <Mist...@nimga.com> 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...) >> >> > -- >> > 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. > > While this may be true in your experience, the C standard imposes no > such restriction. Furthermore, there are systems for which it is not > true. Could you explain how malloc works for such systems please. |
|
|
|
#16 |
|
Messages: n/a
Hébergeur: |
Richard wrote:
> Barry Schwarz <schwarz45@yahoo.com> writes: >>> 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. >> >> While this may be true in your experience, the C standard imposes no >> such restriction. Furthermore, there are systems for which it is not >> true. > > Could you explain how malloc works for such systems please. It returns a `void*`. (If that's not enough of an answer, you'll have to unpack your question.) -- Chris "`essen`, vb, 'to buy many games'" Dollin Hewlett-Packard Limited Cain Road, Bracknell, registered no: registered office: Berks RG12 1HN 690597 England |
|
|
|
#17 |
|
Messages: n/a
Hébergeur: |
Richard wrote:
> Barry Schwarz <schwarz45@yahoo.com> writes: > >> On Oct 22, 2:01 am, "MisterE" <Mist...@nimga.com> 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...) >>> >>> > -- >>> > 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. >> >> While this may be true in your experience, the C standard imposes no >> such restriction. Furthermore, there are systems for which it is not >> true. > > Could you explain how malloc works for such systems please. Because void * is guaranteed to be able to store values of all object pointer types. |
|
|
|
#18 |
|
Messages: n/a
Hébergeur: |
On 22 Oct, 12:51, Barry Schwarz <schwar...@yahoo.com> wrote:
<snip> > (I wonder if there is enough memory in the entire > world to fully populate a system with a 64 BYTE pointer.) 64 x 8 = 512 bits a 512 bit address can address 2^512 locations 2^512 ~ 10^154 the number of atoms in the observable universe is estimated to be ~10^80 so no you couldn't populate your system if you confine yourself to the observable universe -- Nick Keighley |
|
|
|
#19 |
|
Messages: n/a
Hébergeur: |
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...) (Some of these points have been made in other responses, but a few don't seem to have appeared yet.) The Standard guarantees that - Any kind of data pointer can be converted to `void*' and back without changing its value (this implies that no data pointer has more value bits than `void*') - Any function pointer can be converted to any other type of function pointer and back without changing value (hence, all function pointers have the same number of value bits) - The value 0 (the "null pointer constant") is valid for all pointer types, both data pointers and function pointers - `void*' and pointers to all three kinds of `char' have the same size and representation (whatever it is) - All pointers to all struct types have the same size and representation (whatever it is) - All pointers to all union types have the same size and representation (whatever it is) - All non-bit-field objects (hence, all pointers) occupy at least one byte each - A qualified type (`const', etc.) has the same size and representation as its unqualified cousin The Standard does *not* guarantee that all pointers have the same representation or even the same size, and does *not* guarantee that function pointers can be converted to data pointers or vice versa. -- Eric Sosman esosman@ieee-dot-org.invalid |
|
|
|
#20 |
|
Messages: n/a
Hébergeur: |
santosh wrote:
> Richard wrote: > >> Barry Schwarz <schwarz45@yahoo.com> writes: >> >>> On Oct 22, 2:01 am, "MisterE" <Mist...@nimga.com> wrote: >>>> 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. >>> While this may be true in your experience, the C standard imposes no >>> such restriction. Furthermore, there are systems for which it is not >>> true. >> Could you explain how malloc works for such systems please. > Because void * is guaranteed to be able to store values of all object > pointer types. People do seem to get very worried when they find that some of what they thought they knew is in fact false, don't they? The point here is that all the standard requires is that a) there must be a pointer representation (void *) which is capable of pointing to any category of data. malloc() returns its result in such a pointer. b) there must be a valid way of converting from void * to any other pointer type. c) malloc() must ensure that the memory it allocates is suitably aligned for any data type. Nothing requires that the same representation should be used for both the generic pointer type (void *) and all other (data) pointer types. -- Mark "And ASCII isn't required by the standard either" Bluemel |
|
|
|
#21 |
|
Messages: n/a
Hébergeur: |
santosh <santosh.k83@gmail.com> writes:
> Richard wrote: > >> Barry Schwarz <schwarz45@yahoo.com> writes: >> >>> On Oct 22, 2:01 am, "MisterE" <Mist...@nimga.com> 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...) >>>> >>>> > -- >>>> > 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. >>> >>> While this may be true in your experience, the C standard imposes no >>> such restriction. Furthermore, there are systems for which it is not >>> true. >> >> Could you explain how malloc works for such systems please. > > Because void * is guaranteed to be able to store values of all object > pointer types. But we are talking about values of "special memory blocks" where the pointers are different. How does malloc know which "memory type" to allocate? |
|
|
|
#22 |
|
Messages: n/a
Hébergeur: |
Richard wrote:
> santosh <santosh.k83@gmail.com> writes: > >> Richard wrote: >> >>> Barry Schwarz <schwarz45@yahoo.com> writes: >>> >>>> On Oct 22, 2:01 am, "MisterE" <Mist...@nimga.com> 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...) >>>>> >>>>> > -- >>>>> > 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. >>>> >>>> While this may be true in your experience, the C standard imposes >>>> no >>>> such restriction. Furthermore, there are systems for which it is >>>> not true. >>> >>> Could you explain how malloc works for such systems please. >> >> Because void * is guaranteed to be able to store values of all object >> pointer types. > > But we are talking about values of "special memory blocks" where the > pointers are different. How does malloc know which "memory type" to > allocate? It doesn't. It allocates memory suitable for all types. After the conversion to an appropriate pointer type, the memory block is accessed as an array of that type. |
|
|
|
#23 |
|
Messages: n/a
Hébergeur: |
santosh <santosh.k83@gmail.com> writes:
> Richard wrote: > >> santosh <santosh.k83@gmail.com> writes: >> >>> Richard wrote: >>> >>>> Barry Schwarz <schwarz45@yahoo.com> writes: >>>> >>>>> On Oct 22, 2:01 am, "MisterE" <Mist...@nimga.com> 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...) >>>>>> >>>>>> > -- >>>>>> > 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. >>>>> >>>>> While this may be true in your experience, the C standard imposes >>>>> no >>>>> such restriction. Furthermore, there are systems for which it is >>>>> not true. >>>> >>>> Could you explain how malloc works for such systems please. >>> >>> Because void * is guaranteed to be able to store values of all object >>> pointer types. >> >> But we are talking about values of "special memory blocks" where the >> pointers are different. How does malloc know which "memory type" to >> allocate? > > It doesn't. It allocates memory suitable for all types. After the > conversion to an appropriate pointer type, the memory block is accessed > as an array of that type. How can you allocate memory for "all types"? Where is this "special block of memory with extra bits for padding" case? |
|
|
|
#24 |
|
Messages: n/a
Hébergeur: |
Richard <rgrdev@gmail.com> wrote:
> santosh <santosh.k83@gmail.com> writes: > > > Richard wrote: > > > >> Barry Schwarz <schwarz45@yahoo.com> writes: > >> > >>> On Oct 22, 2:01 am, "MisterE" <Mist...@nimga.com> 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...) > >>>> > >>>> 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. > >>> > >>> While this may be true in your experience, the C standard imposes no > >>> such restriction. Furthermore, there are systems for which it is not > >>> true. > >> > >> Could you explain how malloc works for such systems please. > > > > Because void * is guaranteed to be able to store values of all object > > pointer types. > > But we are talking about values of "special memory blocks" where the > pointers are different. No, we're not. We weren't the last time you spouted this nonsensical misinterpretation of C's pointer system, and we still aren't. Nor will we next time you will stubbornly refuse to learn. Richard |
|
|
|
#25 |
|
Messages: n/a
Hébergeur: |
rlb@hoekstra-uitgeverij.nl (Richard Bos) writes:
> Richard <rgrdev@gmail.com> wrote: > >> santosh <santosh.k83@gmail.com> writes: >> >> > Richard wrote: >> > >> >> Barry Schwarz <schwarz45@yahoo.com> writes: >> >> >> >>> On Oct 22, 2:01 am, "MisterE" <Mist...@nimga.com> 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...) >> >>>> >> >>>> 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. >> >>> >> >>> While this may be true in your experience, the C standard imposes no >> >>> such restriction. Furthermore, there are systems for which it is not >> >>> true. >> >> >> >> Could you explain how malloc works for such systems please. >> > >> > Because void * is guaranteed to be able to store values of all object >> > pointer types. >> >> But we are talking about values of "special memory blocks" where the >> pointers are different. > > No, we're not. We weren't the last time you spouted this nonsensical > misinterpretation of C's pointer system, and we still aren't. Nor will > we next time you will stubbornly refuse to learn. > > Richard "there are systems for which it is not true" I ask again : how does malloc know what kind of "special" memory to allocate? Special memory might have these special pointers. And kindly don't accuse me of refusing to learn. If you want to bully someone try someone else. |
|
![]() |
| Outils de la discussion | |
|
|