|
|
Up |
|
|
  |
Author: Eugeny MyunsterEugeny Myunster Date: Apr 30, 2008 09:56
Hello all,
How can i emulate sizeof()
only for integers?
|
| |
|
| | 14 Comments |
|
  |
Author: Eric SosmanEric Sosman Date: Apr 30, 2008 10:18
Eugeny Myunster wrote:
> Hello all,
> How can i emulate sizeof()
> only for integers?
You can look up to sizeof, follow its example in your comings
and goings and doings, seek always to be true to its teachings, and
strive unceasingly in all ways to model your own behavior after that
of sizeof. In any dilemma, ask yourself "What would sizeof do?"
Don't accept easy, cop-out answers (sizeof would not do so, after
all), but spur yourself to deeper and more honest self-examination.
Feed the hungry, heal the sick, give generously to the poor -- in
short[*], emulate sizeof.
[*] A kind of integer, as specified.
|
| |
|
| | no comments |
|
  |
Author: Kenneth BrodyKenneth Brody Date: Apr 30, 2008 10:26
Eugeny Myunster wrote:
>
> Hello all,
> How can i emulate sizeof()
> only for integers?
I'd really love to know which instructors keep giving this assignment.
Why do you want to "emulate sizeof", when sizeof exists just for this
purpose?
How about:
#define MySizeof(x) sizeof(x)
Now you can "emulate sizeof" by using "MySizeof(int)", for example.
--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\ spamcop.net | www.fptech.com | |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: gmail.com>
|
| |
| no comments |
|
  |
Author: Keith ThompsonKeith Thompson Date: Apr 30, 2008 11:41
Kenneth Brody spamcop.net> writes:
> Eugeny Myunster wrote:
>>
>> Hello all,
>> How can i emulate sizeof()
>> only for integers?
>
> I'd really love to know which instructors keep giving this assignment.
>
> Why do you want to "emulate sizeof", when sizeof exists just for this
> purpose?
>
> How about:
>
> #define MySizeof(x) sizeof(x)
>
> Now you can "emulate sizeof" by using "MySizeof(int)", for example.
Except that the macro, unlike the sizeof operator, requires a
parenthesized argument; you can't write "MySizeof 42".
|
| Show full article (2.07Kb) |
| no comments |
|
  |
Author: user923005user923005 Date: Apr 30, 2008 15:06
On Apr 30, 9:56Â am, Eugeny Myunster wrote:
> Hello all,
> Â Â Â Â How can i emulate sizeof()
> Â Â Â Â only for integers?
Of course, it is lunacy to use something else when you want a size,
since the sizeof operator is perfect for that task.
That having been said, you can make an array of 2 objects, and get an
unsigned char pointer to the first and second object and subtract the
pointer difference to find the size.
E.g.
#define StupidEvilTwistedSizeof(type,ans) { \
type a[2]; \
unsigned char *start = (unsigned char *)&a[0]; \
unsigned char *end = (unsigned char *)&a[1]; \
*ans=end-start;}
#include
#include
|
| Show full article (2.35Kb) |
| no comments |
|
  |
Author: user923005user923005 Date: Apr 30, 2008 15:23
On Apr 30, 3:06Â pm, user923005 connx.com> wrote:
> On Apr 30, 9:56Â am, Eugeny Myunster wrote:
>
>> Hello all,
>> Â Â Â Â How can i emulate sizeof()
>> Â Â Â Â only for integers?
>
> Of course, it is lunacy to use something else when you want a size,
> since the sizeof operator is perfect for that task.
>
> That having been said, you can make an array of 2 objects, and get an
> unsigned char pointer to the first and second object and subtract the
> pointer difference to find the size.
>
> E.g.
>
> #define StupidEvilTwistedSizeof(type,ans) { \
> type a[2]; \
> unsigned char *start = (unsigned char *)&a[0]; \
> unsigned char *end = (unsigned char *)&a[1]; \ ...
|
| Show full article (5.64Kb) |
| no comments |
|
  |
Author: user923005user923005 Date: Apr 30, 2008 15:25
On Apr 30, 3:23Â pm, user923005 connx.com> wrote:
> On Apr 30, 3:06Â pm, user923005 connx.com> wrote:
>
>
>
>
>
>> On Apr 30, 9:56Â am, Eugeny Myunster wrote:
>
>>> Hello all,
>>> Â Â Â Â How can i emulate sizeof()
>>> Â Â Â Â only for integers?
>
>> Of course, it is lunacy to use something else when you want a size,
>> since the sizeof operator is perfect for that task.
>
>> That having been said, you can make an array of 2 objects, and get an
>> unsigned char pointer to the first and second object and subtract the
>> pointer difference to find the size.
> ...
|
| Show full article (6.25Kb) |
| no comments |
|
  |
Author: David ThompsonDavid Thompson Date: May 12, 2008 00:41
On Wed, 30 Apr 2008 15:06:16 -0700 (PDT), user923005
connx.com> wrote:
> On Apr 30, 9:56Â am, Eugeny Myunster wrote:
>> Hello all,
>> Â Â Â Â How can i emulate sizeof()
>> Â Â Â Â only for integers?
>
> Of course, it is lunacy to use something else when you want a size,
> since the sizeof operator is perfect for that task.
>
Concur.
> That having been said, you can make an array of 2 objects, and get an
> unsigned char pointer to the first and second object and subtract the
> pointer difference to find the size.
>
You don't even need an array of two: just a single object,
and use the address-one-past. You can't (safely, portably)
_dereference_ that address, but you can compute it.
|
| Show full article (1.38Kb) |
| no comments |
|
  |
Author: Kenny McCormackKenny McCormack Date: May 12, 2008 08:19
In article 4ax.com>,
David Thompson verizon.net> wrote:
>On Wed, 30 Apr 2008 15:06:16 -0700 (PDT), user923005
>connx.com> wrote:
>
>> On Apr 30, 9:56
|
| |
| no comments |
|
  |
|
|
  |
|
|
|
|
|