[eiffel-users] Width of POINTER

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[eiffel-users] Width of POINTER

ctillman
There's something I don't understand.

When I check in a C program on my x86_64 GNU/Linux machine

  const int a[8] = { 0, 1, 2, 3, 4, 5, 6, 7 };
  int i, sum;

  printf ("%lu, %lu", sizeof (a) , sizeof (*a));

I get

  32, 4

In EiffelStudio, when I check {PLATFORM}.Integer_32_bytes I get 4, so times 8 elements I still get 32. But when I check {PLATFORM}.Pointer_bytes, I get 8 rather than 4.

{PLATFORM}.Pointer_bytes comments say "-- Number of bytes in a value of type `POINTER`" ... does this mean the C pointer is a different size than the Eiffel POINTER on this machine?

--
Chris Tillman
Developer

--
You received this message because you are subscribed to the Google Groups "Eiffel Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
Visit this group at https://groups.google.com/group/eiffel-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [eiffel-users] Width of POINTER

'Alexander Kogtenkov' via Eiffel Users
32 printed by the C program means 32 bytes. Given that the array contains 8 elements and each element is 4 bytes, 32 = 8 * 4.

In C, for (complete) arrays, sizeof gives the number of bytes occupied by the whole array. If memory occupied by a pointer is of interest instead, either &a should be used, or a pointer type rather than an array type.

In particular,

    sizeof &a

gives 8 (for variables there is no need to use parentheses, i.e. to write "sizeof (&a)", they are required when the argument is a type, not a variable).

If we had

    extern const int x [];
    const int * y;

the results would be

   sizeof x -- 0 and the compiler raises a warning for me, because the array size is unknown to the compiler (the array type in incomplete)
   sizeof y -- 8

To summarize, the pointer size obtained by "{PLATFORM}.pointer_bytes" or by "sizeof &a" is the same.

Alexander Kogtenkov


Chris Tillman <[hidden email]>:

There's something I don't understand.

When I check in a C program on my x86_64 GNU/Linux machine

  const int a[8] = { 0, 1, 2, 3, 4, 5, 6, 7 };
  int i, sum;

  printf ("%lu, %lu", sizeof (a) , sizeof (*a));

I get

  32, 4

In EiffelStudio, when I check {PLATFORM}.Integer_32_bytes I get 4, so times 8 elements I still get 32. But when I check {PLATFORM}.Pointer_bytes, I get 8 rather than 4.

{PLATFORM}.Pointer_bytes comments say "-- Number of bytes in a value of type `POINTER`" ... does this mean the C pointer is a different size than the Eiffel POINTER on this machine?

--
Chris Tillman
Developer

--
You received this message because you are subscribed to the Google Groups "Eiffel Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
Visit this group at https://groups.google.com/group/eiffel-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [eiffel-users] Width of POINTER

ctillman
Thanks very much. I think it's beginning to soak in.

On Sun, Jun 25, 2017 at 9:44 PM, 'Alexander Kogtenkov' via Eiffel Users <[hidden email]> wrote:
32 printed by the C program means 32 bytes. Given that the array contains 8 elements and each element is 4 bytes, 32 = 8 * 4.

In C, for (complete) arrays, sizeof gives the number of bytes occupied by the whole array. If memory occupied by a pointer is of interest instead, either &a should be used, or a pointer type rather than an array type.

In particular,

    sizeof &a

gives 8 (for variables there is no need to use parentheses, i.e. to write "sizeof (&a)", they are required when the argument is a type, not a variable).

If we had

    extern const int x [];
    const int * y;

the results would be

   sizeof x -- 0 and the compiler raises a warning for me, because the array size is unknown to the compiler (the array type in incomplete)
   sizeof y -- 8

To summarize, the pointer size obtained by "{PLATFORM}.pointer_bytes" or by "sizeof &a" is the same.

Alexander Kogtenkov


Chris Tillman <[hidden email]>:


There's something I don't understand.

When I check in a C program on my x86_64 GNU/Linux machine

  const int a[8] = { 0, 1, 2, 3, 4, 5, 6, 7 };
  int i, sum;

  printf ("%lu, %lu", sizeof (a) , sizeof (*a));

I get

  32, 4

In EiffelStudio, when I check {PLATFORM}.Integer_32_bytes I get 4, so times 8 elements I still get 32. But when I check {PLATFORM}.Pointer_bytes, I get 8 rather than 4.

{PLATFORM}.Pointer_bytes comments say "-- Number of bytes in a value of type `POINTER`" ... does this mean the C pointer is a different size than the Eiffel POINTER on this machine?

--
Chris Tillman
Developer

--
You received this message because you are subscribed to the Google Groups "Eiffel Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
Visit this group at https://groups.google.com/group/eiffel-users.
For more options, visit https://groups.google.com/d/optout.



--
Chris Tillman
Developer

--
You received this message because you are subscribed to the Google Groups "Eiffel Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
Visit this group at https://groups.google.com/group/eiffel-users.
For more options, visit https://groups.google.com/d/optout.
Loading...