Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #10325

Re: Address of array && address of pointer to array

From James Kuyper <jameskuyper@verizon.net>
Newsgroups comp.lang.c
Subject Re: Address of array && address of pointer to array
Date 2011-09-16 09:46 -0400
Organization A noiseless patient Spider
Message-ID <j4vk01$7op$1@dont-email.me> (permalink)
References (2 earlier) <a5df2719-174b-41e0-a39d-659878de44f3@h7g2000yqm.googlegroups.com> <lnvcst8wqv.fsf@nuthaus.mib.org> <3f7eeae9-902e-4d07-865a-9045fdc9159b@hg2g2000vbb.googlegroups.com> <j4u84q$v90$1@dont-email.me> <9fc229b8-6e08-4333-9aec-9e9ae22c9100@eb1g2000vbb.googlegroups.com>

Show all headers | View raw


On 09/16/2011 08:37 AM, Stanley Rice wrote:
> On Sep 16, 9:18�am, James Kuyper <jameskuy...@verizon.net> wrote:
>> On 09/15/2011 09:13 PM, Stanley Rice wrote:
>>
>>> On Sep 16, 2:51 am, Keith Thompson <ks...@mib.org> wrote:
>> ...
>>>> It's likely to work in practice (and I think POSIX requires it
>>>> to work), but there have been systems where function pointers are
>>>> bigger than void*, so the conversion could lose information.
>>
>>> I am not fully understand your meaning of "function pointers are
>>> bigger than void *". I know it's not the size of the pointer.
>>
>> You "know" incorrectly. Function pointers can have a size that is
>> different from the size of void*, and there have been many systems where
>> this is indeed the case.
>> --
>> James Kuyper
> 
> But I try to print sizeof(void *) and sizeof(ptr2fun), supposing that
> ptr2fun
> is a function pointer. It generate the same result, both are 4. So is
> your
> meaning that in some special cases, the size of function pointer and
> the
> pointer to void * is different? And could you explain to me when it
> occurs?

The size of the void* and the size of a given function pointer type are
both implementation-specific, and there's no requirement that they be
the same. On a different implementation, they might be different, and
either one might be larger than the other.

There's only a few cases where the standard imposes any size
requirements. Note that, in C, a byte contains CHAR_BIT bits, and
CHAR_BIT is allowed to be greater than 8. (5.2.4.2.1p1).

The minimum required range of the basic integer type implies a minimum
number of bits needed to store each type (5.2.4.2.1p1):
	short, int: 16 bits
	long: 32 bits
	long long: 64 bits

char and signed char have the same size. (6.2.5p5)

For every signed integer type, the corresponding unsigned integer type
must have the same size. (6.2.5p6)

float _Complex is required to have the same size as float[2]; similarly
for double and long double. (6.2.5p13)

For any given type T:
const T, volatile T, and const volatile T are all required to have the
same size. (6.2.5p26)

For any given pair of compatible types T and U (including T==U as a
special case),
T*, const T*, volatile T*, and const volatile T*, U*, const U*, volatile
U*, and const volatile U* are all required to have the same size. (6.2.5p27)

char*, signed char*, unsigned char*, and void* are all required to have
the same size. (6.2.5p27)

All pointers to structure types have the same size. (6.2.5p27)

All pointers to union types have the same size. (6.2.5p27)

Pointers to other types need NOT have the same size (6.2.5p27)

char, signed char, and unsigned char all have a size of 1 byte (6.5.3.4p3).

The exact-width types, [u]intN_t, take up exactly N bits of memory.
(7.18.1.1p2)
The minimum-width and fastest minimum-width types, [u]int_leastN_t
(7.18.1.2p2) and [u]int_fastN_t (7.18.1.3p2), take up at least N bits of
memory, but possibly more.

The minimum required ranges of certain other types imply a minimum
number of bits (7.18.2.4p1):
	sig_atomic_t, wchar_t: 8 bits
	inptr_t, uintptr_t, ptrdiff_t, size_t, wint_t: 16 bits

float _Imaginary is required to have same size as float; similarly for
double and long double. (Annex Gp4)

For any types not listed above, you should avoid making any assumptions
about their sizes.
-- 
James Kuyper

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Address of array && address of pointer to array Stanley Rice <heconghui@gmail.com> - 2011-09-14 06:12 -0700
  Re: Address of array && address of pointer to array Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-09-14 14:41 +0100
    Re: Address of array && address of pointer to array Paul N <gw7rib@aol.com> - 2011-09-14 14:15 -0700
    Re: Address of array && address of pointer to array Peter Nilsson <airia@acay.com.au> - 2011-09-14 19:25 -0700
      Re: Address of array && address of pointer to array Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-09-15 10:54 +0100
        Re: Address of array && address of pointer to array Stanley Rice <heconghui@gmail.com> - 2011-09-15 05:36 -0700
          Re: Address of array && address of pointer to array Ike Naar <ike@sverige.freeshell.org> - 2011-09-15 13:46 +0000
          Re: Address of array && address of pointer to array Nobody <nobody@nowhere.com> - 2011-09-15 14:48 +0100
            Re: Address of array && address of pointer to array Keith Thompson <kst-u@mib.org> - 2011-09-15 10:28 -0700
              Re: Address of array && address of pointer to array Stanley Rice <heconghui@gmail.com> - 2011-09-15 18:23 -0700
                Re: Address of array && address of pointer to array Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-09-16 12:58 +0100
                Re: Address of array && address of pointer to array James Kuyper <jameskuyper@verizon.net> - 2011-09-16 08:03 -0400
              Re: Address of array && address of pointer to array Nobody <nobody@nowhere.com> - 2011-09-16 13:09 +0100
                Re: Address of array && address of pointer to array Keith Thompson <kst-u@mib.org> - 2011-09-16 12:05 -0700
                Re: Address of array && address of pointer to array gazelle@shell.xmission.com (Kenny McCormack) - 2011-09-16 19:35 +0000
                Re: Address of array && address of pointer to array Peter Nilsson <airia@acay.com.au> - 2011-09-19 15:45 -0700
                Re: Address of array && address of pointer to array Keith Thompson <kst-u@mib.org> - 2011-09-19 17:47 -0700
          Re: Address of array && address of pointer to array James Kuyper <jameskuyper@verizon.net> - 2011-09-15 10:21 -0400
    Re: Address of array && address of pointer to array Stanley Rice <heconghui@gmail.com> - 2011-09-15 05:22 -0700
      Re: Address of array && address of pointer to array James Kuyper <jameskuyper@verizon.net> - 2011-09-15 10:23 -0400
        Re: Address of array && address of pointer to array pete <pfiland@mindspring.com> - 2011-09-15 15:26 -0400
          Re: Address of array && address of pointer to array Stanley Rice <heconghui@gmail.com> - 2011-09-15 18:14 -0700
            Re: Address of array && address of pointer to array Keith Thompson <kst-u@mib.org> - 2011-09-16 02:09 -0700
              Re: Address of array && address of pointer to array James Kuyper <jameskuyper@verizon.net> - 2011-09-16 08:39 -0400
              Re: Address of array && address of pointer to array pete <pfiland@mindspring.com> - 2011-09-16 18:08 -0400
            Re: Address of array && address of pointer to array Bart van Ingen Schenau <bart@ingen.ddns.info> - 2011-09-16 16:38 +0200
              Re: Address of array && address of pointer to array cri@tiac.net (Richard Harter) - 2011-09-16 22:04 +0000
          Re: Address of array && address of pointer to array Stanley Rice <heconghui@gmail.com> - 2011-09-15 18:08 -0700
            Re: Address of array && address of pointer to array Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-09-16 13:12 +0100
            Re: Address of array && address of pointer to array James Kuyper <jameskuyper@verizon.net> - 2011-09-16 08:30 -0400
      Re: Address of array && address of pointer to array Keith Thompson <kst-u@mib.org> - 2011-09-15 11:51 -0700
        Re: Address of array && address of pointer to array Stanley Rice <heconghui@gmail.com> - 2011-09-15 18:13 -0700
          Re: Address of array && address of pointer to array James Kuyper <jameskuyper@verizon.net> - 2011-09-15 21:18 -0400
            Re: Address of array && address of pointer to array Stanley Rice <heconghui@gmail.com> - 2011-09-16 05:37 -0700
              Re: Address of array && address of pointer to array James Kuyper <jameskuyper@verizon.net> - 2011-09-16 09:46 -0400
              Re: Address of array && address of pointer to array Keith Thompson <kst-u@mib.org> - 2011-09-16 12:08 -0700
          Re: Address of array && address of pointer to array Nobody <nobody@nowhere.com> - 2011-09-16 13:20 +0100

csiph-web